承接 youniverse-center/request-validation-bundle 相关项目开发

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

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

youniverse-center/request-validation-bundle

Composer 安装命令:

composer require youniverse-center/request-validation-bundle

包简介

Symfony Bundle for automatic validation of data provided in the request.

README 文档

README

  1. Add validator class implementing Yc\RequestValidationBundle\RequestValidator\RequestValidatorInterface
  • in the getConstriant return constraints used by the validator component
  • in the getGroups return validation groups
  • getInvalidRequestResponse must return response that will be used if the validation has failed.
  1. Add attribute Yc\RequestValidationBundle\Attributes\RequestValidator to your controller
#[Route('/some/route', name: 'some_route')]
#[RequestValidator(Create::class)]
class CreateController extends AbstractController
{
  public function __invoke($data)
  {
    // in the data is your validated request content
  }
}

(This attribute can be also placed on a method if you have multple controllers in a class.)

  1. You probably want to receive data from the request for the validation in your specific way. For this purpose implement Yc\RequestValidationBundle\DataReceiver\DataReceiverInterface

for example:

public function getData(Request $request): mixed
{
    return json_decode($request->getContent(), true);
}
  1. By default the data will be set in the request attribute data if you want to change this, implement Yc\RequestValidationBundle\DataTransformer\DataTransformerInterface

for example:

public function transformData(mixed $data): array
{
    $id = ProjectId::fromString($data['id']);

    return [
        'project' => new Project($id, $data['name'])
    ];
}

and then you can use it in controller like:

public function __invoke(Project $project) {}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固