Symfony api 简化器

维护者

详细信息

github.com/rfrommherz/api

源代码

问题

安装: 1

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2021-12-29 00:36 UTC

This package is auto-updated.

Last update: 2024-09-06 04:09:29 UTC


README

安装

  1. composer req rfrommherz/api
  2. config/bundles.php: 在 bundles.php 中添加新捆绑包
Rf\ApiBundle\JwtBundle::class => ['dev' => true],

使用方法

ApiDto

ApiDto 可以用作控制器中的参数。为了启用对此的支持,您的类必须扩展 ApiDto。每个 ApiDto 都会传递给 symfony 验证器,从而启用对验证注解的支持。

use Rf\ApiBundle\Dto\ApiDto;
use Symfony\Component\Validator\Constraints as Assert;

class Fetch extends ApiDto
{
    /**
     * @Assert\NotBlank
     * @Assert\Url
     * @var string
     */
    private string $repositoryUrl;

参数将自动解析,并可以作为控制器参数传递。

public function index(Fetch $fetch): Response
{
    ...
}
curl --location --request GET 'https:///fetch' \
--header 'Content-Type: application/json' \
--data-raw '{
    "repositoryUrl": "http://...",
}'