zinvapel / symfony-basis-bundle
本包最新版本(0.1.5)的许可证信息不可用。
symfony服务的常用类
0.1.5
2021-03-01 06:37 UTC
Requires
- php: ^7.4 || ^8.0
- zinvapel/enumeration: ^1.0.0
Requires (Dev)
- phpstan/phpstan: ^0.12.59
- sensiolabs/security-checker: ^6.0
- squizlabs/php_codesniffer: ^3.5
- symfony/dependency-injection: ^5.0
- symfony/http-kernel: ^5.0
- symfony/serializer: ^5.0
- symfony/validator: ^5.0
- symfony/yaml: ^5.0
Suggests
- symfony/dependency-injection: If using as Symfony bundle
- symfony/http-kernel: If using as Symfony bundle
- symfony/serializer: If using as Symfony bundle
- symfony/validator: If using as Symfony bundle
- symfony/yaml: If using as Symfony bundle
README
包含创建Symfony应用程序的常用功能。基本上,可以用于任何PHP应用程序。
版本
版本X.Y.Z意味着
- X - 常量1,在概念上没有变化
- Y - 每次更新都包含新功能
- Z - 错误修复
Symfony用户的BasisBundle
将BasisBundle插件到你的bundles.php
。
解释配置
basis: routes: get_user: context: factory_type: denormalize data_extractor: 'route', 'empty', 'json', 'post_json' dto_class: Zinvapel\Basis\BasisBundle\Regular\Dto\Service\EmptyDto constraints_provider: Zinvapel\Basis\BasisBundle\Regular\Dto\Service\EmptyDto::getConstraints service: some.service.name responses: Some\Dto\Name: factory_type: no_content status_code: 204 custom: factory
此配置将生成basis.routes.get_user.controller
服务,即Zinvapel\Basis\BasisBundle\Http\Flow\Controller
的实例。
context.factory_type
定义了工厂,即Zinvapel\Basis\BasisBundle\Http\Flow\Context\Factory\ContextFactoryInterface
的实例。该工厂负责将请求转换为Zinvapel\Basis\BasisBundle\Core\Dto\ServiceDtoInterface
。可以是denormalize
- 从请求中提取数据,验证它并组装ServiceDtoInterface
custom
- 表示从自定义参数中获取服务名称。
context.custom
- 用户定义的工厂。context.data_extractor
定义了从请求中提取数据的方式。可以是route
- 从路由参数中empty
- 返回空数组json
- 从主体中获取JSON并将其转换为关联数组post_json
- 结合route
和json
context.dto_class
定义了将请求转换到的类,即Zinvapel\Basis\BasisBundle\Core\Dto\ServiceDtoInterface
的实例。context.constraints_provider
定义了一个可调用的函数,它返回用于请求验证的Symfony约束数组。service
定义了Zinvapel\Basis\BasisBundle\Core\ServiceInterface
的实例。它表示路由业务逻辑,接受上述ServiceDtoInterface
,返回Zinvapel\Basis\BasisBundle\Core\Dto\StatefulDtoInteface
。responses.Some\Dto\Name
定义了如何将Some\Dto\Name
,即Zinvapel\Basis\BasisBundle\Core\Dto\StatefulDtoInteface
的实例,转换为Symfony响应。responses.X.factory_type
定义了响应工厂,可以是no_content
json
custom
responses.X.status_code
定义了状态码。
使用环境变量ZINVAPEL_BASIS_HTTP_FLOW_DEBUG
强制显示所有HTTP异常
OpenApiAssertionBundle(深度beta版)
从Swagger文档生成断言和类。提供一条命令
$ php bin/console zinvapel:oa:parse-swagger <swagger.yaml> [--target <target> [--class <className>]] Where: <swagger.yaml> - path to yaml file with swagger spec <target> - one of 'full', 'object', 'http' <className> - for target 'object'. Generate just this class
结果示例
- 类
ChatIdMessageMessageIdPatchDto0DtoErrorsItemDto: final class ChatIdMessageMessageIdPatchDto0DtoErrorsItemDto { /** * @Serializer\Groups({"body"}) */ private ?string $path; /** * @Serializer\Groups({"body"}) */ private ?string $error; public function setPath(?string $path = null): self { $this->path = path; return $this; } public function getPath(): ?string { return $this->path; } public function setError(?string $error = null): self { $this->error = error; return $this; } public function getError(): ?string { return $this->error; } }
- 断言
ChatWithStatDto1StatDto: new Assert\Collection([ 'allowExtraFields' => true, 'fields' => [ 'unreadCount' => [ new Assert\Type([ 'type' => 'integer', ]), new Assert\GreaterThanOrEqual([ 'value' => 0, ]), ], 'mentionsCount' => [ new Assert\Type([ 'type' => 'integer', ]), new Assert\GreaterThanOrEqual([ 'value' => 0, ]), ], ], ])