lshamanl / symfony-ui-bundle-command
此包已被弃用且不再维护。作者建议使用 intellect-web-development/symfony-presentation-bundle 包。
Symfony UI Bundle Command (同步,异步)
0.1.4
2021-10-26 11:53 UTC
Requires
- php: >=8.0
- ext-mbstring: *
- composer/package-versions-deprecated: ^1.11
- doctrine/annotations: ^1.13
- doctrine/doctrine-bundle: ^2.4
- doctrine/doctrine-migrations-bundle: ^3.1
- doctrine/orm: ^2.9
- lshamanl/symfony-ui-bundle-foundation: ^0.1
- symfony-bundles/bundle-dependency: ^1.0
- symfony/config: ^5.2
- symfony/dependency-injection: ^5.2
- symfony/serializer: ^5.2
- symfony/translation: ^5.2
- symfony/validator: ^5.2
- zircote/swagger-php: ^3.2
Requires (Dev)
- fakerphp/faker: 1.13.0
- overtrue/phplint: ^3.0
- phpmetrics/phpmetrics: ^2.7
- phpstan/phpstan: ^0.12.81
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.6
README
描述
本包是SymfonyBundle。
本包解决的问题:减轻开发者编写UI入口(控制器、CommandBus等)重复代码的负担。
命令
Sync(同步命令)
示例
use App\Path\To\UseCase as UseCase; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Nelmio\ApiDocBundle\Annotation\Model; use OpenApi\Annotations as OA; use SymfonyBundle\UIBundle\Command\Core\CQRS\Command\Sync\Context as CommandSyncContext; use SymfonyBundle\UIBundle\Command\Core\CQRS\Command\Sync\Processor as CommandSyncProcessor; use SymfonyBundle\UIBundle\Foundation\Core\Contract\ApiFormatter; use SymfonyBundle\UIBundle\Foundation\Core\Dto\OutputFormat; class Controller { /** * @Route(".{_format}", methods={"POST"}, name=".create", defaults={"_format"="json"}) * @OA\Post( * @OA\RequestBody( * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * ref=@Model(type=UseCase\Create\Contract::class) * ) * ) * ) * ) * @OA\Response( * response=200, * description="Create User", * @OA\JsonContent( * allOf={ * @OA\Schema(ref=@Model(type=ApiFormatter::class)), * @OA\Schema(type="object", * @OA\Property( * property="data", * type="object", * @OA\Property( * property="entities", * ref=@Model(type=UseCase\CommonOutputContract::class) * ) * ), * @OA\Property( * property="status", * example="200" * ) * ) * } * ) * ) */ public function create( CommandSyncProcessor $processor, OutputFormat $outputFormat, UseCase\Create\Contract $contract, UseCase\Create\Handler $handler ): Response { $command = new UseCase\Create\Command(); $command->mapContract($contract); $context = new CommandSyncContext( handler: $handler, command: $command, outputFormat: $outputFormat->getFormat(), ); $processor->process($context); return $processor->makeResponse(); } }
Async(异步命令)
示例
use App\Path\To\Entity; use App\Path\To\UseCase as UseCase; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Nelmio\ApiDocBundle\Annotation\Model; use OpenApi\Annotations as OA; use SymfonyBundle\UIBundle\Command\Core\CQRS\Command\Async\Context as CommandAsyncContext; use SymfonyBundle\UIBundle\Command\Core\CQRS\Command\Async\Processor as CommandAsyncProcessor; use SymfonyBundle\UIBundle\Foundation\Core\Contract\ApiFormatter; use SymfonyBundle\UIBundle\Foundation\Core\Dto\OutputFormat; class Controller { /** * @Route(".{_format}", methods={"POST"}, name=".create", defaults={"_format"="json"}) * @OA\Post( * @OA\RequestBody( * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * ref=@Model(type=UseCase\Create\Contract::class) * ) * ) * ) * ) * @OA\Response( * response=200, * description="Create Message", * @OA\JsonContent( * allOf={ * @OA\Schema(ref=@Model(type=ApiFormatter::class)), * @OA\Schema(type="object", * @OA\Property( * property="ok", * example=true * ) * @OA\Property( * property="status", * example="200" * ) * ) * } * ) * ) */ public function create( CommandSyncProcessor $processor, OutputFormat $outputFormat, UseCase\Create\Contract $contract, UseCase\Create\Handler $handler ): Response { $command = new UseCase\Create\Command(); $command->mapContract($contract); $context = new CommandAsyncContext( command: $command, outputFormat: $outputFormat->getFormat(), ); $processor->process($context); return $processor->makeResponse(); }