定制 dentelis/php-json-structure-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dentelis/php-json-structure-validator

Composer 安装命令:

composer require --dev dentelis/php-json-structure-validator

包简介

Json data structure validation framework

README 文档

README

Validator is a lightweight PHP library for validating the structure of data retrieved from an external json API.

The library was originally created for use in acceptance api tests, but can be used anywhere else as well.

Specific

The library was made to test json compatible data structures. Array key validation is not supported.

Installation

Use the package manager composer to install.

composer require dentelis/php-json-structure-validator

Usage

You can use library with(or without) any testing framework you want.

See dentelis/phpunit-json-assert for PhpUnit support.

//object example
$user = (new ObjectType())
    ->addProperty('name', (new StringType())->assertNotEmpty())
    ->addProperty('email', (new StringType())->assertEmail());
    
$data = json_decode('{"name":"user", "email":"user@example.com"}');
try {
    $user->validate($data);
} catch (ValidationException $e) {
    //do smth
    
}

//array of objects
$users = (new ArrayType())
    ->assertNotEmpty()
    ->assertType($user);

$data = json_decode('[{"name":"user", "email":"user@example.com"},{"name":"user", "email":"user@example.com"}]');
try {
    $users->validate($data);
} catch (ValidationException $e) {
    //do smth

}

See examples directory for full example.

Todo

  • more examples
  • proper path in exceptions
  • do not fail on first exception
  • comments translate to english
  • create TypeInterface from Classname (what to do with arrays)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

统计信息

  • 总下载量: 105
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 6
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固