承接 mittwald/psr7-validation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mittwald/psr7-validation

最新稳定版本:v1.1.0

Composer 安装命令:

composer require mittwald/psr7-validation

包简介

PSR-7 middleware for JSON schema validation

README 文档

README

Build Status

Synposis

This package contains a PSR-7 middleware for validating HTTP requests, especially using JSON schema validation.

Warning: This package is still under development; its API can change at any time without notice. Use at own risk.

License

This package is MIT-licensed.

Examples

Validating request bodies using a JSON schema (using the Slim framework):

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        Factory::buildJsonValidatorFromUri('path/to/json-schema.json')
    ));

Validating request bodies using a Swagger specification file:

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        Factory::buildJsonValidatorFromSwaggerDefinition('path/to/swagger.json', 'MyType')
    ));

Validating request bodies using a custom validator (using PHP 7's anonymous classes, for no other reason because I can):

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        new class implements ValidatorInterface {
            public function validateJson($jsonDocument, ValidationResult $result) {
                $result->addErrorForProperty('customernumber', 'Foo');
            }
        }
    ));

Combining multiple validators:

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        new CombinedValidator(
            Factory::buildJsonValidatorFromUri('path/to/schema.json'),
            new MyVerySpecialCustomValidator()
        )
    ));

统计信息

  • 总下载量: 19.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-30