定制 shooktea/request-deserializer-bundle 二次开发

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

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

shooktea/request-deserializer-bundle

Composer 安装命令:

composer require shooktea/request-deserializer-bundle

包简介

Small bundle for deserializing and validating requests from JSON to objects

README 文档

README

Tested on PHP 8.1 with Symfony 6.0.

Installation

Install with Composer:

composer require shooktea/request-deserializer-bundle

And add bundle to bundles.php (if was not added automatically by Symfony Flex):

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    // ...
    ShookTea\RequestDeserializerBundle\ShookTeaRequestDeserializerBundle::class => ['all' => true],
];

How to use it?

  • Create a class implementing ShookTea\RequestDeserializerBundle\Query\QueryInterface (for GET parameters) or ShookTea\RequestDeserializerBundle\Request\RequestInterface (for POST parameters)
  • add annotations from symfony/serializer and symfony/validator components if necessary
  • inject your class to controller method

And that's it!

Example query class: (for GET parameters)

<?php

use ShookTea\RequestDeserializerBundle\Query\QueryInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\SerializedName;

class ExampleQuery implements QueryInterface
{
    #[SerializedName('id')]
    #[Assert\Uuid]
    public string $uuid;
}

Usage in controller:

class ExampleController extends AbstractController
{
    #[Route('/some/route')]
    public function someAction(ExampleQuery $query)
    {
        // do something with query
    }
}

After requesting /some/route?id=217c26de-132e-49f7-a17d-fd80a70e3fe3, in someAction() method of controller, object $query will have a $uuid with value "217c26de-132e-49f7-a17d-fd80a70e3fe3".

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固