From 2482dcc62ea2dd927f70e1e342e23495d118e357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 7 Apr 2025 12:42:28 +0200 Subject: [PATCH] Refactor ExportManager integration and remove ExportsCompilerPass Replaced direct ExportManager dependencies in formatters with an ExportManagerAwareTrait to decouple components and enhance flexibility. Removed the ExportsCompilerPass as it is no longer required, and adjusted service configurations to improve reliability and consistency. --- .../ChillMainBundle/ChillMainBundle.php | 2 - .../CompilerPass/ExportsCompilerPass.php | 102 ------------------ .../ChillMainBundle/Export/ExportManager.php | 63 +++++------ .../Export/ExportManagerAwareInterface.php | 20 ++++ .../Export/Formatter/CSVFormatter.php | 24 ++--- .../Export/Formatter/CSVListFormatter.php | 18 ++-- .../Formatter/CSVPivotedListFormatter.php | 17 ++- .../Export/Formatter/SpreadSheetFormatter.php | 37 +++---- .../Formatter/SpreadsheetListFormatter.php | 22 ++-- .../Export/Helper/ExportManagerAwareTrait.php | 34 ++++++ .../ChillMainBundle/config/services.yaml | 5 +- .../config/services/export.yaml | 12 --- .../FilterListAccompanyingPeriodHelper.php | 2 - 13 files changed, 128 insertions(+), 230 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/DependencyInjection/CompilerPass/ExportsCompilerPass.php create mode 100644 src/Bundle/ChillMainBundle/Export/ExportManagerAwareInterface.php create mode 100644 src/Bundle/ChillMainBundle/Export/Helper/ExportManagerAwareTrait.php diff --git a/src/Bundle/ChillMainBundle/ChillMainBundle.php b/src/Bundle/ChillMainBundle/ChillMainBundle.php index bca92b85c..07d794ee5 100644 --- a/src/Bundle/ChillMainBundle/ChillMainBundle.php +++ b/src/Bundle/ChillMainBundle/ChillMainBundle.php @@ -14,7 +14,6 @@ namespace Chill\MainBundle; use Chill\MainBundle\Cron\CronJobInterface; use Chill\MainBundle\CRUD\CompilerPass\CRUDControllerCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\ACLFlagsCompilerPass; -use Chill\MainBundle\DependencyInjection\CompilerPass\ExportsCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\MenuCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\NotificationCounterCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\SearchableServicesCompilerPass; @@ -66,7 +65,6 @@ class ChillMainBundle extends Bundle $container->addCompilerPass(new SearchableServicesCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new ConfigConsistencyCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new TimelineCompilerClass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); - $container->addCompilerPass(new ExportsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new WidgetsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new NotificationCounterCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new MenuCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/CompilerPass/ExportsCompilerPass.php b/src/Bundle/ChillMainBundle/DependencyInjection/CompilerPass/ExportsCompilerPass.php deleted file mode 100644 index c2126da1e..000000000 --- a/src/Bundle/ChillMainBundle/DependencyInjection/CompilerPass/ExportsCompilerPass.php +++ /dev/null @@ -1,102 +0,0 @@ -has(ExportManager::class)) { - throw new \LogicException('service '.ExportManager::class.' is not defined. It is required by ExportsCompilerPass'); - } - - $chillManagerDefinition = $container->findDefinition( - ExportManager::class - ); - - $this->compileFormatters($chillManagerDefinition, $container); - $this->compileExportElementsProvider($chillManagerDefinition, $container); - } - - private function compileExportElementsProvider( - Definition $chillManagerDefinition, - ContainerBuilder $container, - ) { - $taggedServices = $container->findTaggedServiceIds( - 'chill.export_elements_provider' - ); - - $knownAliases = []; - - foreach ($taggedServices as $id => $tagAttributes) { - foreach ($tagAttributes as $attributes) { - if (!isset($attributes['prefix'])) { - throw new \LogicException("the 'prefix' attribute is missing in your service '{$id}' definition"); - } - - if (array_search($attributes['prefix'], $knownAliases, true)) { - throw new \LogicException('There is already a chill.export_elements_provider service with prefix '.$attributes['prefix'].'. Choose another prefix.'); - } - $knownAliases[] = $attributes['prefix']; - - $chillManagerDefinition->addMethodCall( - 'addExportElementsProvider', - [new Reference($id), $attributes['prefix']] - ); - } - } - } - - private function compileFormatters( - Definition $chillManagerDefinition, - ContainerBuilder $container, - ) { - $taggedServices = $container->findTaggedServiceIds( - 'chill.export_formatter' - ); - - $knownAliases = []; - - foreach ($taggedServices as $id => $tagAttributes) { - foreach ($tagAttributes as $attributes) { - if (!isset($attributes['alias'])) { - throw new \LogicException("the 'alias' attribute is missing in your service '{$id}' definition"); - } - - if (array_search($attributes['alias'], $knownAliases, true)) { - throw new \LogicException('There is already a chill.export_formatter service with alias '.$attributes['alias'].'. Choose another alias.'); - } - $knownAliases[] = $attributes['alias']; - - $chillManagerDefinition->addMethodCall( - 'addFormatter', - [new Reference($id), $attributes['alias']] - ); - } - } - } -} diff --git a/src/Bundle/ChillMainBundle/Export/ExportManager.php b/src/Bundle/ChillMainBundle/Export/ExportManager.php index fbc81caa3..f8ff95fe1 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportManager.php +++ b/src/Bundle/ChillMainBundle/Export/ExportManager.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\MainBundle\Export; -use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\Export\ExportType; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Psr\Log\LoggerInterface; @@ -60,14 +59,13 @@ class ExportManager iterable $exports, iterable $aggregators, iterable $filters, - // iterable $formatters, + iterable $formatters, // iterable $exportElementProvider ) { $this->exports = iterator_to_array($exports); $this->aggregators = iterator_to_array($aggregators); $this->filters = iterator_to_array($filters); - // NOTE: PHP crashes on the next line (exit error code 11). This is desactivated until further investigation - // $this->formatters = iterator_to_array($formatters); + $this->formatters = iterator_to_array($formatters); // foreach ($exportElementProvider as $prefix => $provider) { // $this->addExportElementsProvider($provider, $prefix); @@ -99,7 +97,7 @@ class ExportManager \in_array($filter->applyOn(), $export->supportsModifiers(), true) && $this->isGrantedForElement($filter, $export, $centers) ) { - $filters[$alias] = $filter; + $filters[$alias] = $this->getFilter($alias); } } @@ -133,25 +131,6 @@ class ExportManager return $aggregators; } - public function addExportElementsProvider(ExportElementsProviderInterface $provider, string $prefix): void - { - foreach ($provider->getExportElements() as $suffix => $element) { - $alias = $prefix.'_'.$suffix; - - if ($element instanceof ExportInterface) { - $this->exports[$alias] = $element; - } elseif ($element instanceof FilterInterface) { - $this->filters[$alias] = $element; - } elseif ($element instanceof AggregatorInterface) { - $this->aggregators[$alias] = $element; - } elseif ($element instanceof FormatterInterface) { - $this->addFormatter($element, $alias); - } else { - throw new \LogicException('This element '.$element::class.' is not an instance of export element'); - } - } - } - /** * add a formatter. * @@ -171,11 +150,15 @@ class ExportManager */ public function getAggregator($alias) { - if (!\array_key_exists($alias, $this->aggregators)) { + if (null === $aggregator = $this->aggregators[$alias] ?? null) { throw new \RuntimeException("The aggregator with alias {$alias} is not known."); } - return $this->aggregators[$alias]; + if ($aggregator instanceof ExportManagerAwareInterface) { + $aggregator->setExportManager($this); + } + + return $aggregator; } /** @@ -234,10 +217,10 @@ class ExportManager foreach ($this->exports as $alias => $export) { if ($whereUserIsGranted) { if ($this->isGrantedForElement($export, null, null)) { - yield $alias => $export; + yield $alias => $this->getExport($alias); } } else { - yield $alias => $export; + yield $alias => $this->getExport($alias); } } } @@ -253,9 +236,9 @@ class ExportManager foreach ($this->getExports($whereUserIsGranted) as $alias => $export) { if ($export instanceof GroupedExportInterface) { - $groups[$export->getGroup()][$alias] = $export; + $groups[$export->getGroup()][$alias] = $this->getExport($alias); } else { - $groups['_'][$alias] = $export; + $groups['_'][$alias] = $this->getExport($alias); } } @@ -267,11 +250,15 @@ class ExportManager */ public function getFilter(string $alias): FilterInterface { - if (!\array_key_exists($alias, $this->filters)) { + if (null === $filter = $this->filters[$alias] ?? null) { throw new \RuntimeException("The filter with alias {$alias} is not known."); } - return $this->filters[$alias]; + if ($filter instanceof ExportManagerAwareInterface) { + $filter->setExportManager($this); + } + + return $filter; } public function hasFilter(string $alias): bool @@ -289,7 +276,7 @@ class ExportManager $filters = []; foreach ($this->filters as $alias => $filter) { - $filters[$alias] = $filter; + $filters[$alias] = $this->getFilter($alias); } return $filters; @@ -311,11 +298,15 @@ class ExportManager public function getFormatter(string $alias): FormatterInterface { - if (!\array_key_exists($alias, $this->formatters)) { + if (null === $formatter = $this->formatters[$alias] ?? null) { throw new \RuntimeException("The formatter with alias {$alias} is not known."); } - return $this->formatters[$alias]; + if ($formatter instanceof ExportManagerAwareInterface) { + $formatter->setExportManager($this); + } + + return $formatter; } /** @@ -343,7 +334,7 @@ class ExportManager { foreach ($this->formatters as $alias => $formatter) { if (\in_array($formatter->getType(), $types, true)) { - yield $alias => $formatter; + yield $alias => $this->getFormatter($alias); } } } diff --git a/src/Bundle/ChillMainBundle/Export/ExportManagerAwareInterface.php b/src/Bundle/ChillMainBundle/Export/ExportManagerAwareInterface.php new file mode 100644 index 000000000..f4e43d206 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Export/ExportManagerAwareInterface.php @@ -0,0 +1,20 @@ +exportManager = $manager; - } + ) {} /** * @uses appendAggregatorForm */ public function buildForm(FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases) { - $aggregators = $this->exportManager->getAggregators($aggregatorAliases); + $aggregators = $this->getExportManager()->getAggregators($aggregatorAliases); $nb = \count($aggregatorAliases); foreach ($aggregators as $alias => $aggregator) { @@ -99,7 +95,7 @@ class CSVFormatter implements FormatterInterface $descriptions = []; foreach ($this->filtersData as $key => $filterData) { - $statement = $this->exportManager + $statement = $this->getExportManager() ->getFilter($key) ->describeAction($filterData); @@ -137,8 +133,8 @@ class CSVFormatter implements FormatterInterface ) { $this->result = $result; $this->orderingHeaders($formatterData); - $this->export = $this->exportManager->getExport($exportAlias); - $this->aggregators = iterator_to_array($this->exportManager + $this->export = $this->getExportManager()->getExport($exportAlias); + $this->aggregators = iterator_to_array($this->getExportManager() ->getAggregators(array_keys($aggregatorsData))); $this->exportData = $exportData; $this->aggregatorsData = $aggregatorsData; diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/CSVListFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/CSVListFormatter.php index 0bd4c6713..3582da66a 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/CSVListFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/CSVListFormatter.php @@ -11,8 +11,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Formatter; -use Chill\MainBundle\Export\ExportManager; +use Chill\MainBundle\Export\ExportManagerAwareInterface; use Chill\MainBundle\Export\FormatterInterface; +use Chill\MainBundle\Export\Helper\ExportManagerAwareTrait; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Response; @@ -24,16 +25,14 @@ use function count; /** * Create a CSV List for the export. */ -class CSVListFormatter implements FormatterInterface +class CSVListFormatter implements FormatterInterface, ExportManagerAwareInterface { + use ExportManagerAwareTrait; + protected $exportAlias; protected $exportData; - /** - * @var ExportManager - */ - protected $exportManager; protected $formatterData; @@ -51,10 +50,9 @@ class CSVListFormatter implements FormatterInterface */ protected $translator; - public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager) + public function __construct(TranslatorInterface $translatorInterface) { $this->translator = $translatorInterface; - $this->exportManager = $exportManager; } /** @@ -199,7 +197,7 @@ class CSVListFormatter implements FormatterInterface */ protected function prepareCacheLabels() { - $export = $this->exportManager->getExport($this->exportAlias); + $export = $this->getExportManager()->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach ($keys as $key) { @@ -217,7 +215,7 @@ class CSVListFormatter implements FormatterInterface */ protected function prepareHeaders($output) { - $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); + $keys = $this->getExportManager()->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = \count($this->result) > 0 ? $this->result[0] : []; $header_line = []; diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/CSVPivotedListFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/CSVPivotedListFormatter.php index ce8f44f0a..5fbf4a006 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/CSVPivotedListFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/CSVPivotedListFormatter.php @@ -11,8 +11,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Formatter; -use Chill\MainBundle\Export\ExportManager; +use Chill\MainBundle\Export\ExportManagerAwareInterface; use Chill\MainBundle\Export\FormatterInterface; +use Chill\MainBundle\Export\Helper\ExportManagerAwareTrait; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Response; @@ -22,17 +23,14 @@ use Symfony\Contracts\Translation\TranslatorInterface; * Create a CSV List for the export where the header are printed on the * first column, and the result goes from left to right. */ -class CSVPivotedListFormatter implements FormatterInterface +class CSVPivotedListFormatter implements FormatterInterface, ExportManagerAwareInterface { + use ExportManagerAwareTrait; + protected $exportAlias; protected $exportData; - /** - * @var ExportManager - */ - protected $exportManager; - protected $formatterData; /** @@ -49,10 +47,9 @@ class CSVPivotedListFormatter implements FormatterInterface */ protected $translator; - public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager) + public function __construct(TranslatorInterface $translatorInterface) { $this->translator = $translatorInterface; - $this->exportManager = $exportManager; } /** @@ -198,7 +195,7 @@ class CSVPivotedListFormatter implements FormatterInterface */ protected function prepareCacheLabels() { - $export = $this->exportManager->getExport($this->exportAlias); + $export = $this->getExportManager()->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach ($keys as $key) { diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php index e1c2f067b..300e48b93 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php @@ -11,8 +11,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Formatter; -use Chill\MainBundle\Export\ExportManager; +use Chill\MainBundle\Export\ExportManagerAwareInterface; use Chill\MainBundle\Export\FormatterInterface; +use Chill\MainBundle\Export\Helper\ExportManagerAwareTrait; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\FormType; @@ -20,17 +21,17 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; -class SpreadSheetFormatter implements FormatterInterface +class SpreadSheetFormatter implements FormatterInterface, ExportManagerAwareInterface { + use ExportManagerAwareTrait; + /** * an array where keys are the aggregators aliases and * values are the data. * * replaced when `getResponse` is called. - * - * @var type */ - protected $aggregatorsData; + protected array $aggregatorsData; /** * The export. @@ -41,12 +42,6 @@ class SpreadSheetFormatter implements FormatterInterface */ protected $export; - /** - * replaced when `getResponse` is called. - * - * @var type - */ - // protected $aggregators; /** * array containing value of export form. @@ -57,11 +52,6 @@ class SpreadSheetFormatter implements FormatterInterface */ protected $exportData; - /** - * @var ExportManager - */ - protected $exportManager; - /** * replaced when `getResponse` is called. * @@ -72,7 +62,7 @@ class SpreadSheetFormatter implements FormatterInterface /** * replaced when `getResponse` is called. * - * @var type + * @var array */ protected $formatterData; @@ -120,10 +110,9 @@ class SpreadSheetFormatter implements FormatterInterface */ private bool $cacheDisplayableResultIsInitialized = false; - public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager) + public function __construct(TranslatorInterface $translatorInterface) { $this->translator = $translatorInterface; - $this->exportManager = $exportManager; } public function buildForm( @@ -142,7 +131,7 @@ class SpreadSheetFormatter implements FormatterInterface ]); // ordering aggregators - $aggregators = $this->exportManager->getAggregators($aggregatorAliases); + $aggregators = $this->getExportManager()->getAggregators($aggregatorAliases); $nb = \count($aggregatorAliases); foreach ($aggregators as $alias => $aggregator) { @@ -174,7 +163,7 @@ class SpreadSheetFormatter implements FormatterInterface { $data = ['format' => 'xlsx']; - $aggregators = iterator_to_array($this->exportManager->getAggregators($aggregatorAliases)); + $aggregators = iterator_to_array($this->getExportManager()->getAggregators($aggregatorAliases)); foreach (array_keys($aggregators) as $index => $alias) { $data[$alias] = ['order' => $index + 1]; } @@ -198,7 +187,7 @@ class SpreadSheetFormatter implements FormatterInterface // store all data when the process is initiated $this->result = $result; $this->formatterData = $formatterData; - $this->export = $this->exportManager->getExport($exportAlias); + $this->export = $this->getExportManager()->getExport($exportAlias); $this->exportData = $exportData; $this->filtersData = $filtersData; $this->aggregatorsData = $aggregatorsData; @@ -258,7 +247,7 @@ class SpreadSheetFormatter implements FormatterInterface $line = 3; foreach ($this->filtersData as $alias => $data) { - $filter = $this->exportManager->getFilter($alias); + $filter = $this->getExportManager()->getFilter($alias); $description = $filter->describeAction($data, 'string'); if (\is_array($description)) { @@ -474,7 +463,7 @@ class SpreadSheetFormatter implements FormatterInterface } // keys for aggregator foreach ($this->aggregatorsData as $alias => $data) { - $aggregator = $this->exportManager->getAggregator($alias); + $aggregator = $this->getExportManager()->getAggregator($alias); foreach ($aggregator->getQueryKeys($data) as $key) { $keysExportElementAssociation[$key] = [$aggregator, $data]; diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php index fe236a295..e34eab2ea 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php @@ -11,8 +11,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Formatter; -use Chill\MainBundle\Export\ExportManager; +use Chill\MainBundle\Export\ExportManagerAwareInterface; use Chill\MainBundle\Export\FormatterInterface; +use Chill\MainBundle\Export\Helper\ExportManagerAwareTrait; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; @@ -21,24 +22,18 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; -use function count; - -// command to get the report with curl : curl --user "center a_social:password" "http://localhost:8000/fr/exports/generate/count_person?export[filters][person_gender_filter][enabled]=&export[filters][person_nationality_filter][enabled]=&export[filters][person_nationality_filter][form][nationalities]=&export[aggregators][person_nationality_aggregator][order]=1&export[aggregators][person_nationality_aggregator][form][group_by_level]=country&export[submit]=&export[_token]=RHpjHl389GrK-bd6iY5NsEqrD5UKOTHH40QKE9J1edU" --globoff /** * Create a CSV List for the export. */ -class SpreadsheetListFormatter implements FormatterInterface +class SpreadsheetListFormatter implements FormatterInterface, ExportManagerAwareInterface { + use ExportManagerAwareTrait; + protected $exportAlias; protected $exportData; - /** - * @var ExportManager - */ - protected $exportManager; - protected $formatterData; /** @@ -55,10 +50,9 @@ class SpreadsheetListFormatter implements FormatterInterface */ protected $translator; - public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager) + public function __construct(TranslatorInterface $translatorInterface) { $this->translator = $translatorInterface; - $this->exportManager = $exportManager; } /** @@ -258,7 +252,7 @@ class SpreadsheetListFormatter implements FormatterInterface */ protected function prepareCacheLabels() { - $export = $this->exportManager->getExport($this->exportAlias); + $export = $this->getExportManager()->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach ($keys as $key) { @@ -280,7 +274,7 @@ class SpreadsheetListFormatter implements FormatterInterface */ protected function prepareHeaders(Worksheet $worksheet) { - $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); + $keys = $this->getExportManager()->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = \count($this->result) > 0 ? $this->result[0] : []; $header_line = []; diff --git a/src/Bundle/ChillMainBundle/Export/Helper/ExportManagerAwareTrait.php b/src/Bundle/ChillMainBundle/Export/Helper/ExportManagerAwareTrait.php new file mode 100644 index 000000000..eb89f7970 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Export/Helper/ExportManagerAwareTrait.php @@ -0,0 +1,34 @@ +exportManager = $exportManager; + } + + public function getExportManager(): ExportManager + { + if (null === $this->exportManager) { + throw new ExportRuntimeException('ExportManager not set'); + } + + return $this->exportManager; + } +} diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index a9829f99d..14f0f851a 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -89,10 +89,7 @@ services: $exports: !tagged_iterator { tag: chill.export, index_by: alias } $aggregators: !tagged_iterator { tag: chill.export_aggregator, index_by: alias } $filters: !tagged_iterator { tag: chill.export_filter, index_by: alias } - # for an unknown reason, iterator_to_array($formatter) cause a segmentation fault error (php-fpm code 11). removed temporarily - # $formatters: !tagged_iterator { tag: chill.export_formatter, index_by: alias } - # remove until we can properly test it - # $exportElementProvider: !tagged_iterator { tag: chill.export_elements_provider, index_by: prefix } + $formatters: !tagged_iterator { tag: chill.export_formatter, index_by: alias } Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface: '@Chill\MainBundle\Security\Resolver\CenterResolverDispatcher' diff --git a/src/Bundle/ChillMainBundle/config/services/export.yaml b/src/Bundle/ChillMainBundle/config/services/export.yaml index b0f34a159..2bda5a191 100644 --- a/src/Bundle/ChillMainBundle/config/services/export.yaml +++ b/src/Bundle/ChillMainBundle/config/services/export.yaml @@ -31,33 +31,21 @@ services: chill.main.export.spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadSheetFormatter - arguments: - $translatorInterface: '@Symfony\Contracts\Translation\TranslatorInterface' - $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadsheet' } chill.main.export.list_formatter: class: Chill\MainBundle\Export\Formatter\CSVListFormatter - arguments: - $translatorInterface: '@Symfony\Contracts\Translation\TranslatorInterface' - $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csvlist' } chill.main.export.list_spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadsheetListFormatter - arguments: - $translatorInterface: '@Symfony\Contracts\Translation\TranslatorInterface' - $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadlist' } chill.main.export.pivoted_list_formatter: class: Chill\MainBundle\Export\Formatter\CSVPivotedListFormatter - arguments: - $translatorInterface: '@Symfony\Contracts\Translation\TranslatorInterface' - $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csv_pivoted_list' } diff --git a/src/Bundle/ChillPersonBundle/Export/Helper/FilterListAccompanyingPeriodHelper.php b/src/Bundle/ChillPersonBundle/Export/Helper/FilterListAccompanyingPeriodHelper.php index ed390b652..50cc00092 100644 --- a/src/Bundle/ChillPersonBundle/Export/Helper/FilterListAccompanyingPeriodHelper.php +++ b/src/Bundle/ChillPersonBundle/Export/Helper/FilterListAccompanyingPeriodHelper.php @@ -19,7 +19,6 @@ use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\QueryBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\Security\Core\Security; /** * Filter accompanying period list and related, removing confidential ones @@ -30,7 +29,6 @@ final readonly class FilterListAccompanyingPeriodHelper implements FilterListAcc private bool $filterStatsByCenters; public function __construct( - private Security $security, private CenterRepositoryInterface $centerRepository, private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser, ParameterBagInterface $parameterBag,