Browse Source

exports: minor fixes

Olivier Massot 3 years ago
parent
commit
bcd83c2c5b

+ 14 - 10
src/Service/Export/BaseExporter.php

@@ -21,12 +21,10 @@ use Twig\Environment;
  */
 abstract class BaseExporter implements ExporterInterface
 {
-    const TEMPLATE = '';
-
     // dependencies injections
     protected AccessRepository $accessRepository;
     protected Environment $twig;
-    protected EncoderIterator $encoderHandler;
+    protected EncoderIterator $encoderIterator;
     protected EntityManagerInterface $entityManager;
     protected TemporaryFileStorage $storage;
     protected LoggerInterface $logger;
@@ -36,7 +34,7 @@ abstract class BaseExporter implements ExporterInterface
     #[Required]
     public function setTwig(Environment $twig) { $this->twig = $twig; }
     #[Required]
-    public function setEncoderHandler(EncoderIterator $encoderHandler) { $this->encoderHandler = $encoderHandler; }
+    public function setEncoderIterator(EncoderIterator $encoderIterator) { $this->encoderIterator = $encoderIterator; }
     #[Required]
     public function setEntityManager(EntityManagerInterface $entityManager) { $this->entityManager = $entityManager; }
     #[Required]
@@ -111,7 +109,7 @@ abstract class BaseExporter implements ExporterInterface
      * @return ExportModelInterface
      * @throws Exception
      */
-    function buildModel(ExportRequest $exportRequest): ExportModelInterface
+    protected function buildModel(ExportRequest $exportRequest): ExportModelInterface
     {
         throw new Exception('not implemented error');
     }
@@ -125,8 +123,14 @@ abstract class BaseExporter implements ExporterInterface
      */
     protected function getBasename(): string
     {
+        $arr = explode('\\', static::class);
+        $classname = end($arr);
         return StringsUtils::camelToSnake(
-            preg_replace('/^([\w\d]+)Exporter$/', '$1', self::class, 1)
+            preg_replace(
+                '/^([\w\d]+)Exporter$/',
+                '$1',
+                $classname,
+                1)
         );
     }
 
@@ -145,11 +149,11 @@ abstract class BaseExporter implements ExporterInterface
      * @return string Rendu HTML
      * @throws Exception
      */
-    function render(ExportModelInterface $model): string
+    protected function render(ExportModelInterface $model): string
     {
         try {
             return $this->twig->render(
-                '@templates/export/licence_cmf.html.twig',
+                $this->getTemplatePath(),
                 ['model' => $model]
             );
         }
@@ -168,7 +172,7 @@ abstract class BaseExporter implements ExporterInterface
      */
     protected function encode(string $html, string $format): string
     {
-        $encoder = $this->encoderHandler->getEncoderFor($format);
+        $encoder = $this->encoderIterator->getEncoderFor($format);
         return $encoder->encode($html);
     }
 
@@ -189,7 +193,7 @@ abstract class BaseExporter implements ExporterInterface
      * @return mixed
      * @throws Exception
      */
-    function store(string $name, string $content): string
+    protected function store(string $name, string $content): string
     {
         return $this->storage->write($name, $content);
     }

+ 0 - 2
src/Service/Export/Encoder/EncoderInterface.php

@@ -2,8 +2,6 @@
 
 namespace App\Service\Export\Encoder;
 
-use App\ApiResources\Export\ExportRequest;
-
 interface EncoderInterface
 {
     public function support(string $format): bool;

+ 2 - 10
src/Service/Export/LicenceCmfExporter.php

@@ -5,26 +5,18 @@ namespace App\Service\Export;
 
 use App\ApiResources\Export\ExportRequest;
 use App\ApiResources\Export\LicenceCmf\LicenceCmfOrganizationER;
-use App\Service\Export\Encoder\EncoderIterator;
 use App\Service\Export\Model\ExportModelInterface;
 use App\Service\Export\Model\LicenceCmf;
 use App\Enum\Access\FunctionEnum;
-use App\Repository\Access\AccessRepository;
 use App\Repository\Organization\OrganizationRepository;
 use App\Service\Export\Model\LicenceCmfCollection;
-use App\Service\Storage\TemporaryFileStorage;
 use App\Service\Storage\UploadStorage;
-use Doctrine\ORM\EntityManagerInterface;
-use Psr\Log\LoggerInterface;
-use Twig\Environment;
 
 /**
  * Exporte la licence CMF de la structure ou du ou des access, au format demandé
  */
 class LicenceCmfExporter extends BaseExporter implements ExporterInterface
 {
-    const TEMPLATE = '@templates/export/licence_cmf.html.twig';
-
     const CMF_ID = 12097;
 
     /**
@@ -44,7 +36,7 @@ class LicenceCmfExporter extends BaseExporter implements ExporterInterface
         return $exportRequest instanceof LicenceCmfOrganizationER;
     }
 
-    function buildModel(ExportRequest $exportRequest): LicenceCmfCollection
+    protected function buildModel(ExportRequest $exportRequest): LicenceCmfCollection
     {
         $organization = $this->accessRepository->find($exportRequest->getRequesterId())->getOrganization();
 
@@ -55,7 +47,7 @@ class LicenceCmfExporter extends BaseExporter implements ExporterInterface
         $licenceCmf->setOrganizationName($organization->getName());
         $licenceCmf->setOrganizationIdentifier($organization->getIdentifier());
 
-        $parentFederation = $organization->getNetworkOrganizations()[0]->getParent();
+        $parentFederation = $organization->getNetworkOrganizations()->get(0)->getParent();
         $licenceCmf->setFederationName($parentFederation->getName());
 
         $licenceCmf->setColor(

+ 6 - 0
tests/Service/Export/LicenceCmfExporterTest.php

@@ -0,0 +1,6 @@
+<?php
+
+class LicenceCmfExporterTest
+{
+
+}