From a43b740ba077ca65097d2c1c7c68857aac6724c8 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Fri, 6 Oct 2017 15:35:02 +0200 Subject: [PATCH] Register definition encoders. --- .../Pass/RegisterEncodersPass.php | 44 +++++++++++++++++++ src/NetzmachtContaoLeafletBundle.php | 2 + 2 files changed, 46 insertions(+) create mode 100644 src/DependencyInjection/Pass/RegisterEncodersPass.php diff --git a/src/DependencyInjection/Pass/RegisterEncodersPass.php b/src/DependencyInjection/Pass/RegisterEncodersPass.php new file mode 100644 index 0000000..4281f4e --- /dev/null +++ b/src/DependencyInjection/Pass/RegisterEncodersPass.php @@ -0,0 +1,44 @@ + + * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE + * @filesource + */ + +declare(strict_types=1); + +namespace Netzmacht\Contao\Leaflet\DependencyInjection\Pass; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Register all definition encoders. + * + * @package Netzmacht\Contao\Leaflet\DependencyInjection\Pass + */ +class RegisterEncodersPass implements CompilerPassInterface +{ + /** + * {@inheritDoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('netzmacht.contao_leaflet_maps.definition.builder.event_dispatcher')) { + return; + } + + $definition = $container->getDefinition('netzmacht.contao_leaflet_maps.definition.builder.event_dispatcher'); + $serviceIds = $container->findTaggedServiceIds('netzmacht.contao_leaflet_maps.encoder'); + + foreach ($serviceIds as $serviceId => $tags) { + $definition->addMethodCall('addSubscriber', [new Reference($serviceId)]); + } + } +} diff --git a/src/NetzmachtContaoLeafletBundle.php b/src/NetzmachtContaoLeafletBundle.php index e067424..77e1336 100644 --- a/src/NetzmachtContaoLeafletBundle.php +++ b/src/NetzmachtContaoLeafletBundle.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Netzmacht\Contao\Leaflet; use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterDefinitionMapperPass; +use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterEncodersPass; use Netzmacht\Contao\Toolkit\DependencyInjection\CompilerPass\AddTaggedServicesAsArgumentCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -32,6 +33,7 @@ class NetzmachtContaoLeafletBundle extends Bundle public function build(ContainerBuilder $container) { $container->addCompilerPass(new RegisterDefinitionMapperPass()); + $container->addCompilerPass(new RegisterEncodersPass()); $container->addCompilerPass( new AddTaggedServicesAsArgumentCompilerPass(