Introduce service names constants.

This commit is contained in:
David Molineus
2016-10-05 15:30:55 +02:00
parent 436cf88901
commit 971f905ad2
11 changed files with 138 additions and 38 deletions

View File

@@ -10,9 +10,12 @@
*/ */
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Netzmacht\Contao\Leaflet\Alias\UnderscoreFilter;
use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\Boot;
use Netzmacht\Contao\Leaflet\ContaoAssets; 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\MapElement;
use Netzmacht\Contao\Leaflet\Frontend\MapModule; use Netzmacht\Contao\Leaflet\Frontend\MapModule;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; 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. * 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( return new MapProvider(
$container['leaflet.definition.mapper'], $container[LeafletServices::DEFINITION_MAPPER],
$container['leaflet.definition.builder'], $container[LeafletServices::DEFINITION_BUILDER],
$container['event-dispatcher'], $container[Services::EVENT_DISPATCHER],
$container['input'], $container[Services::INPUT],
$container['leaflet.map.assets'] $container[LeafletServices::MAP_ASSETS]
); );
}); });
/* /*
* Contao assets handler. Loads Leaflet assets as contao (static) 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(); return new ContaoAssets();
}); });
/* /*
* The leaflet boot. * The leaflet boot.
*/ */
$container['leaflet.boot'] = $container->share(function ($container) { $container[LeafletServices::BOOT] = $container->share(function ($container) {
return new Boot($container['event-dispatcher']); return new Boot($container[Services::EVENT_DISPATCHER]);
}); });
/* /*
* The definition mapper. * The definition mapper.
*/ */
$container['leaflet.definition.mapper'] = $container->share(function ($container) { $container[LeafletServices::DEFINITION_MAPPER] = $container->share(function ($container) {
/** @var Boot $boot */ /** @var Boot $boot */
$boot = $container['leaflet.boot']; $boot = $container[LeafletServices::BOOT];
$mapper = new DefinitionMapper($container['event-dispatcher']); $mapper = new DefinitionMapper($container[Services::EVENT_DISPATCHER]);
return $boot->initializeDefinitionMapper($mapper); 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. * 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 */ /** @var Boot $boot */
$boot = $container['leaflet.boot']; $boot = $container[LeafletServices::BOOT];
$dispatcher = new EventDispatcher(); $dispatcher = new EventDispatcher();
return $boot->initializeEventDispatcher($dispatcher); 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. * The javascript encoder factory being used for building the map javascript.
*/ */
$container['leaflet.definition.builder.encoder-factory'] = function ($container) { $container[LeafletServices::DEFINITION_ENCODER_FACTORY] = function ($container) {
$dispatcher = $container['leaflet.definition.builder.event-dispatcher']; $dispatcher = $container[LeafletServices::DEFINITION_BUILDER_EVENT_DISPATCHER];
return function (Output $output) use ($dispatcher) { return function (Output $output) use ($dispatcher) {
$encoder = new ChainEncoder(); $encoder = new ChainEncoder();
@@ -108,11 +111,11 @@ $container['leaflet.definition.builder.encoder-factory'] = function ($container)
/* /*
* The leaflet builder transforms the definition to javascript. * 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 */ /** @var Boot $boot */
$boot = $container['leaflet.boot']; $boot = $container[LeafletServices::BOOT];
$dispatcher = $container['leaflet.definition.builder.event-dispatcher']; $dispatcher = $container[LeafletServices::DEFINITION_BUILDER_EVENT_DISPATCHER];
$factory = $container['leaflet.definition.builder.encoder-factory']; $factory = $container[LeafletServices::DEFINITION_ENCODER_FACTORY];
$builder = new Builder($factory); $builder = new Builder($factory);
$leaflet = new Leaflet($builder, $dispatcher, array(), JSON_UNESCAPED_SLASHES ^ Flags::BUILD_STACK); $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); 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]); 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 * @return \Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator
*/ */
$container['leaflet.alias-generator'] = $container->share( $container[LeafletServices::ALIAS_GENERATOR] = $container->share(
function ($container) { function ($container) {
return function ($dataContainerName, $aliasField, $fields) use ($container) { return function ($dataContainerName, $aliasField, $fields) use ($container) {
$filters = [ $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( $container['leaflet.dca.map-callbacks'] = $container->share(
function ($container) { function ($container) {
return new \Netzmacht\Contao\Leaflet\Dca\MapCallbacks( return new MapCallbacks(
$container[Services::DCA_MANAGER], $container[Services::DCA_MANAGER],
$container[Services::DATABASE_CONNECTION] $container[Services::DATABASE_CONNECTION]
); );
} }
); );
/**
* Callback helper class for tl_leaflet_layer.
*
* @return LayerCallbacks
*/
$container['leaflet.dca.layer-callbacks'] = $container->share( $container['leaflet.dca.layer-callbacks'] = $container->share(
function ($container) { function ($container) {
return new \Netzmacht\Contao\Leaflet\Dca\LayerCallbacks( return new LayerCallbacks(
$container[Services::DCA_MANAGER], $container[Services::DCA_MANAGER],
$container[Services::DATABASE_CONNECTION], $container[Services::DATABASE_CONNECTION],
$GLOBALS['LEAFLET_LAYERS'] $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( $container['leaflet.dca.control-callbacks'] = $container->share(
function ($container) { function ($container) {
return new \Netzmacht\Contao\Leaflet\Dca\ControlCallbacks( return new ControlCallbacks(
$container[Services::DCA_MANAGER], $container[Services::DCA_MANAGER],
$container[Services::DATABASE_CONNECTION] $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) { $container[Services::CONTENT_ELEMENTS_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) {
return new MapElement( return new MapElement(
$model, $model,
$container->get(Services::TEMPLATE_FACTORY), $container->get(Services::TEMPLATE_FACTORY),
$container->get(Services::TRANSLATOR), $container->get(Services::TRANSLATOR),
$container->get('leaflet.map.provider'), $container->get(LeafletServices::MAP_PROVIDER),
$container->get(Services::INPUT), $container->get(Services::INPUT),
$container->get(Services::CONFIG), $container->get(Services::CONFIG),
$column $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) { $container[Services::MODULES_MAP]['leaflet'] = function ($model, $column, ContainerInterface $container) {
return new MapModule( return new MapModule(
$model, $model,
$container->get(Services::TEMPLATE_FACTORY), $container->get(Services::TEMPLATE_FACTORY),
$container->get(Services::TRANSLATOR), $container->get(Services::TRANSLATOR),
$container->get('leaflet.map.provider'), $container->get(LeafletServices::MAP_PROVIDER),
$container->get(Services::INPUT), $container->get(Services::INPUT),
$container->get(Services::CONFIG), $container->get(Services::CONFIG),
$column $column

View File

@@ -167,7 +167,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'tl_leaflet_control', 'tl_leaflet_control',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -178,7 +178,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'tl_leaflet_icon', 'tl_leaflet_icon',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -265,7 +265,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'tl_leaflet_layer', 'tl_leaflet_layer',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -167,7 +167,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'tl_leaflet_map', 'tl_leaflet_map',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -176,7 +176,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'tl_leaflet_marker', 'tl_leaflet_marker',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -164,7 +164,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array
'tl_leaflet_popup', 'tl_leaflet_popup',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -157,7 +157,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array
'tl_leaflet_style', 'tl_leaflet_style',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -202,7 +202,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
'tl_leaflet_vector', 'tl_leaflet_vector',
'alias', 'alias',
['title'], ['title'],
'leaflet.alias-generator' \Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::ALIAS_GENERATOR
), ),
), ),
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true), 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50', 'unique' => true),

View File

@@ -10,7 +10,14 @@
namespace Netzmacht\Contao\Leaflet\DependencyInjection; namespace Netzmacht\Contao\Leaflet\DependencyInjection;
use Netzmacht\Contao\Leaflet\Boot;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; 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. * Class LeafletServices describes services provided by the leaflet package.
@@ -19,6 +26,62 @@ use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
*/ */
class LeafletServices 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. * Service name of the frontend value filter.
* *

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Subscriber; namespace Netzmacht\Contao\Leaflet\Subscriber;
use ContaoCommunityAlliance\Contao\EventDispatcher\EventDispatcherInitializer; use ContaoCommunityAlliance\Contao\EventDispatcher\EventDispatcherInitializer;
use Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices;
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent; use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
use Netzmacht\Contao\Leaflet\Event\InitializeDefinitionMapperEvent; use Netzmacht\Contao\Leaflet\Event\InitializeDefinitionMapperEvent;
use Netzmacht\Contao\Leaflet\Event\InitializeEventDispatcherEvent; use Netzmacht\Contao\Leaflet\Event\InitializeEventDispatcherEvent;
@@ -58,7 +59,7 @@ class BootSubscriber implements EventSubscriberInterface
{ {
$container = $event->getContainer(); $container = $event->getContainer();
$debugMode = $container->get(Services::CONFIG)->get('debugMode'); $debugMode = $container->get(Services::CONFIG)->get('debugMode');
$mapProvider = $container->get('leaflet.map.provider'); $mapProvider = $container->get(LeafletServices::MAP_PROVIDER);
$parser = new LeafletInsertTagParser($mapProvider, $debugMode); $parser = new LeafletInsertTagParser($mapProvider, $debugMode);
$container->get(Services::INSERT_TAG_REPLACER)->registerParser($parser); $container->get(Services::INSERT_TAG_REPLACER)->registerParser($parser);
@@ -154,7 +155,7 @@ class BootSubscriber implements EventSubscriberInterface
if ($collection) { if ($collection) {
/** @var DefinitionMapper $mapper */ /** @var DefinitionMapper $mapper */
$mapper = $GLOBALS['container']['leaflet.definition.mapper']; $mapper = $GLOBALS['container'][LeafletServices::DEFINITION_MAPPER];
$buffer = ''; $buffer = '';
$icons = array(); $icons = array();