From 1b035901c138639472902aba69353661174d192c Mon Sep 17 00:00:00 2001 From: David Molineus Date: Fri, 6 Oct 2017 15:16:02 +0200 Subject: [PATCH] Register definition mappers. --- .../Pass/RegisterDefinitionMapperPass.php | 50 +++++++++++++++++++ src/NetzmachtContaoLeafletBundle.php | 3 ++ 2 files changed, 53 insertions(+) create mode 100644 src/DependencyInjection/Pass/RegisterDefinitionMapperPass.php diff --git a/src/DependencyInjection/Pass/RegisterDefinitionMapperPass.php b/src/DependencyInjection/Pass/RegisterDefinitionMapperPass.php new file mode 100644 index 0000000..0a34f95 --- /dev/null +++ b/src/DependencyInjection/Pass/RegisterDefinitionMapperPass.php @@ -0,0 +1,50 @@ + + * @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 mappers. + * + * @package Netzmacht\Contao\Leaflet\DependencyInjection\Pass + */ +class RegisterDefinitionMapperPass implements CompilerPassInterface +{ + /** + * {@inheritDoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('netzmacht.contao_leaflet_maps.definition.mapper')) { + return; + } + + $definition = $container->getDefinition('netzmacht.contao_leaflet_maps.definition.mapper'); + $taggedServices = $container->findTaggedServiceIds('netzmacht.contao_leaflet_maps.mapper '); + + foreach ($taggedServices as $serviceId => $tags) { + foreach ($tags as $attributes) { + if (isset($attributes['priority'])) { + $definition->addMethodCall('register', [new Reference($serviceId), (int) $attributes['priority']]); + } else { + $definition->addMethodCall('register', [new Reference($serviceId)]); + } + } + } + } +} diff --git a/src/NetzmachtContaoLeafletBundle.php b/src/NetzmachtContaoLeafletBundle.php index 9c2c089..e067424 100644 --- a/src/NetzmachtContaoLeafletBundle.php +++ b/src/NetzmachtContaoLeafletBundle.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Netzmacht\Contao\Leaflet; +use Netzmacht\Contao\Leaflet\DependencyInjection\Pass\RegisterDefinitionMapperPass; use Netzmacht\Contao\Toolkit\DependencyInjection\CompilerPass\AddTaggedServicesAsArgumentCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -30,6 +31,8 @@ class NetzmachtContaoLeafletBundle extends Bundle */ public function build(ContainerBuilder $container) { + $container->addCompilerPass(new RegisterDefinitionMapperPass()); + $container->addCompilerPass( new AddTaggedServicesAsArgumentCompilerPass( 'netzmacht.contao_leaflet_maps.layer_label_renderer',