mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 14:07:43 +00:00
210 lines
7.3 KiB
PHP
210 lines
7.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
|
|
|
use LogicException;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\Definition;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
/**
|
|
* Compiles the services tagged with :
|
|
*
|
|
* - chill.export
|
|
* - chill.export_formatter
|
|
* - chill.export_aggregator
|
|
* - chill.export_filter
|
|
* - chill.export_elements_provider
|
|
*/
|
|
class ExportsCompilerPass implements CompilerPassInterface
|
|
{
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
if (!$container->has('Chill\MainBundle\Export\ExportManager')) {
|
|
throw new LogicException('service Chill\MainBundle\Export\ExportManager '
|
|
. 'is not defined. It is required by ExportsCompilerPass');
|
|
}
|
|
|
|
$chillManagerDefinition = $container->findDefinition(
|
|
'Chill\MainBundle\Export\ExportManager'
|
|
);
|
|
|
|
//$this->compileExports($chillManagerDefinition, $container);
|
|
//$this->compileFilters($chillManagerDefinition, $container);
|
|
//$this->compileAggregators($chillManagerDefinition, $container);
|
|
//$this->compileFormatters($chillManagerDefinition, $container);
|
|
//$this->compileExportElementsProvider($chillManagerDefinition, $container);
|
|
}
|
|
|
|
private function compileAggregators(
|
|
Definition $chillManagerDefinition,
|
|
ContainerBuilder $container
|
|
) {
|
|
$taggedServices = $container->findTaggedServiceIds(
|
|
'chill.export_aggregator'
|
|
);
|
|
|
|
$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_aggregator service with alias '
|
|
. $attributes['alias'] . '. Choose another alias.');
|
|
}
|
|
$knownAliases[] = $attributes['alias'];
|
|
|
|
$chillManagerDefinition->addMethodCall(
|
|
'addAggregator',
|
|
[new Reference($id), $attributes['alias']]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
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 compileExports(
|
|
Definition $chillManagerDefinition,
|
|
ContainerBuilder $container
|
|
) {
|
|
$taggedServices = $container->findTaggedServiceIds(
|
|
'chill.export'
|
|
);
|
|
|
|
$knownAliases = [];
|
|
|
|
foreach ($taggedServices as $id => $tagAttributes) {
|
|
|
|
if (!$container->has($id)) {
|
|
dump('the service was removed');
|
|
continue;
|
|
}
|
|
|
|
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 service with alias '
|
|
. $attributes['alias'] . '. Choose another alias.');
|
|
}
|
|
$knownAliases[] = $attributes['alias'];
|
|
|
|
$chillManagerDefinition->addMethodCall(
|
|
'addExport',
|
|
[new Reference($id), $attributes['alias']]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function compileFilters(
|
|
Definition $chillManagerDefinition,
|
|
ContainerBuilder $container
|
|
) {
|
|
$taggedServices = $container->findTaggedServiceIds(
|
|
'chill.export_filter'
|
|
);
|
|
|
|
$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_filter service with alias '
|
|
. $attributes['alias'] . '. Choose another alias.');
|
|
}
|
|
$knownAliases[] = $attributes['alias'];
|
|
|
|
$chillManagerDefinition->addMethodCall(
|
|
'addFilter',
|
|
[new Reference($id), $attributes['alias']]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
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']]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|