zinvapel/symfony-basis-bundle

本包最新版本(0.1.5)的许可证信息不可用。

symfony服务的常用类

安装: 83

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

0.1.5 2021-03-01 06:37 UTC

This package is auto-updated.

Last update: 2024-09-29 05:56:09 UTC


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 - 结合routejson
  • 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,
            ]),
        ],
    ],
])