From 971f905ad2dda757ea91605d83f3314bcebf0c1b Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 5 Oct 2016 15:30:55 +0200 Subject: [PATCH] Introduce service names constants. --- module/config/services.php | 92 +++++++++++++------ module/dca/tl_leaflet_control.php | 2 +- module/dca/tl_leaflet_icon.php | 2 +- module/dca/tl_leaflet_layer.php | 2 +- module/dca/tl_leaflet_map.php | 2 +- module/dca/tl_leaflet_marker.php | 2 +- module/dca/tl_leaflet_popup.php | 2 +- module/dca/tl_leaflet_style.php | 2 +- module/dca/tl_leaflet_vector.php | 2 +- .../DependencyInjection/LeafletServices.php | 63 +++++++++++++ .../Leaflet/Subscriber/BootSubscriber.php | 5 +- 11 files changed, 138 insertions(+), 38 deletions(-) diff --git a/module/config/services.php b/module/config/services.php index a648fac..b33168a 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -10,9 +10,12 @@ */ use Interop\Container\ContainerInterface; -use Netzmacht\Contao\Leaflet\Alias\UnderscoreFilter; use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\ContaoAssets; +use Netzmacht\Contao\Leaflet\Dca\ControlCallbacks; +use Netzmacht\Contao\Leaflet\Dca\LayerCallbacks; +use Netzmacht\Contao\Leaflet\Dca\MapCallbacks; +use Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices; use Netzmacht\Contao\Leaflet\Frontend\MapElement; use Netzmacht\Contao\Leaflet\Frontend\MapModule; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; @@ -40,38 +43,38 @@ global $container; /* * Leaflet map provider is a simply api entry to to get the leaflet map from the database. */ -$container['leaflet.map.provider'] = $container->share(function ($container) { +$container[LeafletServices::MAP_PROVIDER] = $container->share(function ($container) { return new MapProvider( - $container['leaflet.definition.mapper'], - $container['leaflet.definition.builder'], - $container['event-dispatcher'], - $container['input'], - $container['leaflet.map.assets'] + $container[LeafletServices::DEFINITION_MAPPER], + $container[LeafletServices::DEFINITION_BUILDER], + $container[Services::EVENT_DISPATCHER], + $container[Services::INPUT], + $container[LeafletServices::MAP_ASSETS] ); }); /* * Contao assets handler. Loads Leaflet assets as contao (static) assets. */ -$container['leaflet.map.assets'] = $container->share(function () { +$container[LeafletServices::MAP_ASSETS] = $container->share(function () { return new ContaoAssets(); }); /* * The leaflet boot. */ -$container['leaflet.boot'] = $container->share(function ($container) { - return new Boot($container['event-dispatcher']); +$container[LeafletServices::BOOT] = $container->share(function ($container) { + return new Boot($container[Services::EVENT_DISPATCHER]); }); /* * The definition mapper. */ -$container['leaflet.definition.mapper'] = $container->share(function ($container) { +$container[LeafletServices::DEFINITION_MAPPER] = $container->share(function ($container) { /** @var Boot $boot */ - $boot = $container['leaflet.boot']; - $mapper = new DefinitionMapper($container['event-dispatcher']); + $boot = $container[LeafletServices::BOOT]; + $mapper = new DefinitionMapper($container[Services::EVENT_DISPATCHER]); return $boot->initializeDefinitionMapper($mapper); }); @@ -80,9 +83,9 @@ $container['leaflet.definition.mapper'] = $container->share(function ($container /* * The local event dispatcher is used for the leaflet javascript encoding system. */ -$container['leaflet.definition.builder.event-dispatcher'] = $container->share(function ($container) { +$container[LeafletServices::DEFINITION_BUILDER_EVENT_DISPATCHER] = $container->share(function ($container) { /** @var Boot $boot */ - $boot = $container['leaflet.boot']; + $boot = $container[LeafletServices::BOOT]; $dispatcher = new EventDispatcher(); return $boot->initializeEventDispatcher($dispatcher); @@ -91,8 +94,8 @@ $container['leaflet.definition.builder.event-dispatcher'] = $container->share(fu /* * The javascript encoder factory being used for building the map javascript. */ -$container['leaflet.definition.builder.encoder-factory'] = function ($container) { - $dispatcher = $container['leaflet.definition.builder.event-dispatcher']; +$container[LeafletServices::DEFINITION_ENCODER_FACTORY] = function ($container) { + $dispatcher = $container[LeafletServices::DEFINITION_BUILDER_EVENT_DISPATCHER]; return function (Output $output) use ($dispatcher) { $encoder = new ChainEncoder(); @@ -108,11 +111,11 @@ $container['leaflet.definition.builder.encoder-factory'] = function ($container) /* * The leaflet builder transforms the definition to javascript. */ -$container['leaflet.definition.builder'] = $container->share(function($container) { +$container[LeafletServices::DEFINITION_BUILDER] = $container->share(function($container) { /** @var Boot $boot */ - $boot = $container['leaflet.boot']; - $dispatcher = $container['leaflet.definition.builder.event-dispatcher']; - $factory = $container['leaflet.definition.builder.encoder-factory']; + $boot = $container[LeafletServices::BOOT]; + $dispatcher = $container[LeafletServices::DEFINITION_BUILDER_EVENT_DISPATCHER]; + $factory = $container[LeafletServices::DEFINITION_ENCODER_FACTORY]; $builder = new Builder($factory); $leaflet = new Leaflet($builder, $dispatcher, array(), JSON_UNESCAPED_SLASHES ^ Flags::BUILD_STACK); @@ -120,7 +123,7 @@ $container['leaflet.definition.builder'] = $container->share(function($container return $boot->initializeLeafletBuilder($leaflet); }); -$container['leaflet.frontend.value-filter'] = $container->share(function($container) { +$container[LeafletServices::FRONTEND_VALUE_FILTER] = $container->share(function($container) { return new ValueFilter($container[Services::INSERT_TAG_REPLACER]); }); @@ -129,7 +132,7 @@ $container['leaflet.frontend.value-filter'] = $container->share(function($contai * * @return \Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator */ -$container['leaflet.alias-generator'] = $container->share( +$container[LeafletServices::ALIAS_GENERATOR] = $container->share( function ($container) { return function ($dataContainerName, $aliasField, $fields) use ($container) { $filters = [ @@ -149,18 +152,28 @@ $container['leaflet.alias-generator'] = $container->share( } ); +/** + * Callback helper class for tl_leaflet_map. + * + * @return MapCallbacks + */ $container['leaflet.dca.map-callbacks'] = $container->share( function ($container) { - return new \Netzmacht\Contao\Leaflet\Dca\MapCallbacks( + return new MapCallbacks( $container[Services::DCA_MANAGER], $container[Services::DATABASE_CONNECTION] ); } ); +/** + * Callback helper class for tl_leaflet_layer. + * + * @return LayerCallbacks + */ $container['leaflet.dca.layer-callbacks'] = $container->share( function ($container) { - return new \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks( + return new LayerCallbacks( $container[Services::DCA_MANAGER], $container[Services::DATABASE_CONNECTION], $GLOBALS['LEAFLET_LAYERS'] @@ -168,33 +181,56 @@ $container['leaflet.dca.layer-callbacks'] = $container->share( } ); +/** + * Callback helper class for tl_leaflet_control. + * + * @return ControlCallbacks + */ $container['leaflet.dca.control-callbacks'] = $container->share( function ($container) { - return new \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks( + return new ControlCallbacks( $container[Services::DCA_MANAGER], $container[Services::DATABASE_CONNECTION] ); } ); +/** + * Component factory for content element. + * + * @param ContentModel $model Content model. + * @param string $column Template section. + * @param ContainerInterface $container Container. + * + * @return MapElement + */ $container[Services::CONTENT_ELEMENTS_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) { return new MapElement( $model, $container->get(Services::TEMPLATE_FACTORY), $container->get(Services::TRANSLATOR), - $container->get('leaflet.map.provider'), + $container->get(LeafletServices::MAP_PROVIDER), $container->get(Services::INPUT), $container->get(Services::CONFIG), $column ); }; +/** + * Component factory for frontend module. + * + * @param ModuleModel $model Module model. + * @param string $column Template section. + * @param ContainerInterface $container Container. + * + * @return MapModule + */ $container[Services::MODULES_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) { return new MapModule( $model, $container->get(Services::TEMPLATE_FACTORY), $container->get(Services::TRANSLATOR), - $container->get('leaflet.map.provider'), + $container->get(LeafletServices::MAP_PROVIDER), $container->get(Services::INPUT), $container->get(Services::CONFIG), $column diff --git a/module/dca/tl_leaflet_control.php b/module/dca/tl_leaflet_control.php index 385a7b7..e8ea7f5 100644 --- a/module/dca/tl_leaflet_control.php +++ b/module/dca/tl_leaflet_control.php @@ -167,7 +167,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'tl_leaflet_control', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_icon.php b/module/dca/tl_leaflet_icon.php index 260f7d1..c2cecaf 100644 --- a/module/dca/tl_leaflet_icon.php +++ b/module/dca/tl_leaflet_icon.php @@ -178,7 +178,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'tl_leaflet_icon', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index 5d7e73e..e9c9cf7 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -265,7 +265,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'tl_leaflet_layer', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_map.php b/module/dca/tl_leaflet_map.php index e03fdd8..ea63030 100644 --- a/module/dca/tl_leaflet_map.php +++ b/module/dca/tl_leaflet_map.php @@ -167,7 +167,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'tl_leaflet_map', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_marker.php b/module/dca/tl_leaflet_marker.php index 26b413d..f2d9dac 100644 --- a/module/dca/tl_leaflet_marker.php +++ b/module/dca/tl_leaflet_marker.php @@ -176,7 +176,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'tl_leaflet_marker', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_popup.php b/module/dca/tl_leaflet_popup.php index 1d62e9e..25deb2d 100644 --- a/module/dca/tl_leaflet_popup.php +++ b/module/dca/tl_leaflet_popup.php @@ -164,7 +164,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array 'tl_leaflet_popup', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_style.php b/module/dca/tl_leaflet_style.php index 1d68f46..967dc05 100644 --- a/module/dca/tl_leaflet_style.php +++ b/module/dca/tl_leaflet_style.php @@ -157,7 +157,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'tl_leaflet_style', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/module/dca/tl_leaflet_vector.php b/module/dca/tl_leaflet_vector.php index df68fff..207123b 100644 --- a/module/dca/tl_leaflet_vector.php +++ b/module/dca/tl_leaflet_vector.php @@ -202,7 +202,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'tl_leaflet_vector', 'alias', ['title'], - 'leaflet.alias-generator' + \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR ), ), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), diff --git a/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php b/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php index 66e4cfe..a08229a 100644 --- a/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php +++ b/src/Netzmacht/Contao/Leaflet/DependencyInjection/LeafletServices.php @@ -10,7 +10,14 @@ namespace Netzmacht\Contao\Leaflet\DependencyInjection; +use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; +use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\MapProvider; +use Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator; +use Netzmacht\LeafletPHP\Assets; +use Netzmacht\LeafletPHP\Leaflet; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class LeafletServices describes services provided by the leaflet package. @@ -19,6 +26,62 @@ use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; */ class LeafletServices { + /** + * Service name for the alias generator which creates valid js aliases. + * + * @return AliasGenerator + */ + const ALIAS_GENERATOR = 'leaflet.alias-generator'; + + /** + * Service name of the boot handler. + * + * @return Boot + */ + const BOOT = 'leaflet.boot'; + + /** + * Service name of the definition builder. + * + * @return Leaflet + */ + const DEFINITION_BUILDER = 'leaflet.definition.builder'; + + /** + * Service name of the encoder factory used inside of the definition builder. + * + * @return \callable + */ + const DEFINITION_ENCODER_FACTORY = 'leaflet.definition.builder.encoder-factory'; + + /** + * Service name of the internal used event dispatcher of the definition builder. + * + * @return EventDispatcherInterface + */ + const DEFINITION_BUILDER_EVENT_DISPATCHER = 'leaflet.definition.builder.event-dispatcher'; + + /** + * Service name of the definition mapper. + * + * @return DefinitionMapper + */ + const DEFINITION_MAPPER = 'leaflet.definition.mapper'; + + /** + * Service name of the leaflet map provider. + * + * @return MapProvider + */ + const MAP_PROVIDER = 'leaflet.map.provider'; + + /** + * Service name of the map assets handler. + * + * @return Assets + */ + const MAP_ASSETS = 'leaflet.map.assets'; + /** * Service name of the frontend value filter. * diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php index 34ef4dc..fd192c5 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php @@ -12,6 +12,7 @@ namespace Netzmacht\Contao\Leaflet\Subscriber; use ContaoCommunityAlliance\Contao\EventDispatcher\EventDispatcherInitializer; +use Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices; use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent; use Netzmacht\Contao\Leaflet\Event\InitializeDefinitionMapperEvent; use Netzmacht\Contao\Leaflet\Event\InitializeEventDispatcherEvent; @@ -58,7 +59,7 @@ class BootSubscriber implements EventSubscriberInterface { $container = $event->getContainer(); $debugMode = $container->get(Services::CONFIG)->get('debugMode'); - $mapProvider = $container->get('leaflet.map.provider'); + $mapProvider = $container->get(LeafletServices::MAP_PROVIDER); $parser = new LeafletInsertTagParser($mapProvider, $debugMode); $container->get(Services::INSERT_TAG_REPLACER)->registerParser($parser); @@ -154,7 +155,7 @@ class BootSubscriber implements EventSubscriberInterface if ($collection) { /** @var DefinitionMapper $mapper */ - $mapper = $GLOBALS['container']['leaflet.definition.mapper']; + $mapper = $GLOBALS['container'][LeafletServices::DEFINITION_MAPPER]; $buffer = ''; $icons = array();