lshamanl / symfony-ui-bundle-command
Symfony UI Bundle Command (Sync, Async)
Installs: 124
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
Описание:
Данный пакет является Симфони-бандлом.
Проблема, которую решает данный пакет: Снимает с разработчика необходимость писать повторяющийся код в UI-точках входа в приложение(Controllers, CommandBus), далее Controller.
Command:
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(); }