<?php
namespace App\EventSubscriber\VOD\ExportGenerator;
use App\Contract\VOD\ExportFileHandler\FileHandlerInterface;
use App\Event\VOD\ExportGenerator\ExportEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FileHandlerSubscriber implements EventSubscriberInterface
{
/**
* The custom file handler service responsible for copying the file in specified location.
*
* @var \App\Contract\VOD\ExportFileHandler\FileHandlerInterface
*/
private $fileHandler;
public function __construct(FileHandlerInterface $fileHandler)
{
$this->fileHandler = $fileHandler;
}
public static function getSubscribedEvents(): array
{
return [
ExportEvent::class => 'onExportFileGenerated',
];
}
/**
* Public callback for the export event.
*
* Responsible for moving the generated file to given location, based on the environment.
* For the local/dev environment, the NullHandler will be used, so the file won't be
* copied anywhere, but for production, we will use the AwsHandler in order to copy
* the file in a dedicated bucket.
*
* @param \App\Event\VOD\ExportGenerator\ExportEvent $event
* The instance of the dispatched event
*/
public function onExportFileGenerated(ExportEvent $event): void
{
$this->fileHandler->processEntity($event->getEntity());
}
}