| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- declare(strict_types=1);
- namespace App\State\Processor\Organization;
- use ApiPlatform\Metadata\Delete;
- use ApiPlatform\Metadata\Operation;
- use ApiPlatform\State\ProcessorInterface;
- use App\ApiResources\Organization\OrganizationCreationRequest;
- use App\ApiResources\Organization\OrganizationDeletionRequest;
- use App\Message\Command\OrganizationCreationCommand;
- use App\Service\Organization\OrganizationFactory;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Messenger\MessageBusInterface;
- class OrganizationDeletionRequestProcessor implements ProcessorInterface
- {
- public function __construct(
- private readonly MessageBusInterface $messageBus,
- private readonly OrganizationFactory $organizationFactory,
- ) {}
- /**
- * @param OrganizationDeletionRequest $organizationDeletionRequest
- * @param mixed[] $uriVariables
- * @param mixed[] $context
- *
- * @throws \Exception
- */
- public function process(mixed $organizationDeletionRequest, Operation $operation, array $uriVariables = [], array $context = []): OrganizationCreationRequest
- {
- if (!$operation instanceof Delete) {
- throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
- }
- if ($organizationDeletionRequest->isAsync()) {
- // Send the export request to Messenger (@see App\Message\Handler\OrganizationCreationHandler)
- $this->messageBus->dispatch(
- new OrganizationDeletionCommand($organizationDeletionRequest)
- );
- } else {
- // For testing purposes only
- $this->organizationFactory->delete($organizationDeletionRequest);
- }
- return $organizationDeletionRequest;
- }
- }
|