|
|
@@ -5,27 +5,44 @@ namespace App\Service\Export;
|
|
|
use App\ApiResources\Export\ExportRequest;
|
|
|
use App\Entity\Core\File;
|
|
|
use App\Enum\Export\ExportFormatEnum;
|
|
|
-use App\Service\Export\Encoder\EncoderHandler;
|
|
|
+use App\Repository\Access\AccessRepository;
|
|
|
use App\Service\Export\Model\ExportModelInterface;
|
|
|
+use App\Service\ServiceIterator\EncoderIterator;
|
|
|
use App\Service\Storage\TemporaryFileStorage;
|
|
|
+use App\Service\Utils\StringsUtils;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Exception;
|
|
|
+use Psr\Log\LoggerInterface;
|
|
|
+use Symfony\Contracts\Service\Attribute\Required;
|
|
|
use Twig\Environment;
|
|
|
|
|
|
/**
|
|
|
* Classe de base des services d'export
|
|
|
*/
|
|
|
-class BaseExporter implements ExporterInterface
|
|
|
+abstract class BaseExporter implements ExporterInterface
|
|
|
{
|
|
|
- const TEMPLATE = '@templates/export/licence_cmf.html.twig';
|
|
|
-
|
|
|
- public function __construct(
|
|
|
- private Environment $twig,
|
|
|
- private EncoderHandler $encoderHandler,
|
|
|
- private EntityManagerInterface $entityManager,
|
|
|
- private TemporaryFileStorage $storage
|
|
|
- )
|
|
|
- {}
|
|
|
+ const TEMPLATE = '';
|
|
|
+
|
|
|
+ // dependencies injections
|
|
|
+ protected AccessRepository $accessRepository;
|
|
|
+ protected Environment $twig;
|
|
|
+ protected EncoderIterator $encoderHandler;
|
|
|
+ protected EntityManagerInterface $entityManager;
|
|
|
+ protected TemporaryFileStorage $storage;
|
|
|
+ protected LoggerInterface $logger;
|
|
|
+
|
|
|
+ #[Required]
|
|
|
+ public function setAccessRepository(AccessRepository $accessRepository) { $this->accessRepository = $accessRepository; }
|
|
|
+ #[Required]
|
|
|
+ public function setTwig(Environment $twig) { $this->twig = $twig; }
|
|
|
+ #[Required]
|
|
|
+ public function setEncoderHandler(EncoderIterator $encoderHandler) { $this->encoderHandler = $encoderHandler; }
|
|
|
+ #[Required]
|
|
|
+ public function setEntityManager(EntityManagerInterface $entityManager) { $this->entityManager = $entityManager; }
|
|
|
+ #[Required]
|
|
|
+ public function setStorage(TemporaryFileStorage $storage) { $this->storage = $storage; }
|
|
|
+ #[Required]
|
|
|
+ public function setLogger(LoggerInterface $logger) { $this->logger = $logger; }
|
|
|
|
|
|
public function support(ExportRequest $exportRequest): bool
|
|
|
{
|
|
|
@@ -62,11 +79,15 @@ class BaseExporter implements ExporterInterface
|
|
|
// Met à jour l'enregistrement du fichier en base
|
|
|
// <-- [refactoring] cette partie pourrait être faite en amont du service
|
|
|
$file = new File();
|
|
|
- $file->setOrganization($exportRequest->getRequester()->getOrganization());
|
|
|
+
|
|
|
+ $requesterId = $exportRequest->getRequesterId();
|
|
|
+ $organization = $this->accessRepository->find($requesterId)->getOrganization();
|
|
|
+
|
|
|
+ $file->setOrganization($organization);
|
|
|
$file->setVisibility('NOBODY');
|
|
|
$file->setFolder('DOCUMENTS');
|
|
|
$file->setCreateDate(new \DateTime());
|
|
|
- $file->setCreatedBy($exportRequest->getRequester()->getId());
|
|
|
+ $file->setCreatedBy($requesterId);
|
|
|
// -->
|
|
|
// <-- [refactoring] cette partie doit être faite après la création du fichier (storage ? service ?)
|
|
|
$file->setType('LICENCE_CMF');
|
|
|
@@ -95,6 +116,28 @@ class BaseExporter implements ExporterInterface
|
|
|
throw new Exception('not implemented error');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Retourne le nom par défaut de cet export,
|
|
|
+ * utilisé pour trouver le template twig ou encore pour nommer
|
|
|
+ * le fichier exporté.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function getBasename(): string
|
|
|
+ {
|
|
|
+ return StringsUtils::camelToSnake(
|
|
|
+ preg_replace('/^([\w\d]+)Exporter$/', '$1', self::class, 1)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Return the path of the twig template for this export
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function getTemplatePath(): string {
|
|
|
+ return '@templates/export/' . $this->getBasename() . '.html.twig';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Fait le render du template twig à partir du modèle de données
|
|
|
*
|
|
|
@@ -137,7 +180,7 @@ class BaseExporter implements ExporterInterface
|
|
|
*/
|
|
|
protected function getFileBasename(ExportModelInterface $model): string
|
|
|
{
|
|
|
- return strtolower($model::class);
|
|
|
+ return $this->getBasename();
|
|
|
}
|
|
|
|
|
|
/**
|