| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- declare(strict_types=1);
- namespace App\Message\Handler;
- use App\Message\Command\Export;
- use App\Service\ServiceIterator\ExporterIterator;
- use Symfony\Component\Mercure\HubInterface;
- use Symfony\Component\Mercure\Update;
- use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
- use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
- class ExportHandler implements MessageHandlerInterface
- {
- public function __construct(
- private ExporterIterator $handler,
- private HubInterface $mercureHub
- ) {}
- public function __invoke(Export $export)
- {
- $exportRequest = $export->getExportRequest();
- try {
- $exportService = $this->handler->getExporterFor($exportRequest);
- $file = $exportService->export($exportRequest);
- $update = new Update('files', json_encode(['url' => 'https://my.download.url/' . $file->getId()]));
- $this->mercureHub->publish($update);
- } catch (\Exception $e) {
- // To prevent Messenger from retrying
- throw new UnrecoverableMessageHandlingException($e->getMessage(), $e->getCode(), $e);
- }
- }
- }
|