diff --git a/module/config/config.php b/module/config/config.php index c0c54ad..1cd3c47 100644 --- a/module/config/config.php +++ b/module/config/config.php @@ -110,20 +110,36 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\Loading $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\FullscreenControlMapper'; // Vector mappers. -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\PolylineMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\MultiPolylineMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\PolygonMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\MultiPolygonMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\CircleMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\CircleMarkerMapper'; -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Vector\RectangleMapper'; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\PolylineMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\MultiPolylineMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\PolygonMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\MultiPolygonMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\CircleMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\CircleMarkerMapper($container->getFrontendValueFilter()); +}; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new Netzmacht\Contao\Leaflet\Mapper\Vector\RectangleMapper($container->getFrontendValueFilter()); +}; // Miscellaneous mappers. -$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\UI\PopupMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Type\ImageIconMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Type\DivIconMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Style\FixedStyleMapper'; +$GLOBALS['LEAFLET_MAPPERS'][] = function (\Netzmacht\Contao\Leaflet\ServiceContainer $container) { + return new \Netzmacht\Contao\Leaflet\Mapper\UI\MarkerMapper($container->getFrontendValueFilter()); +}; /* * Leaflet encoders. diff --git a/module/config/services.php b/module/config/services.php index 7578338..e5670a8 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -18,7 +18,6 @@ use Netzmacht\Contao\Leaflet\MapService; use Netzmacht\Contao\Leaflet\ServiceContainer; use Netzmacht\JavascriptBuilder\Builder; use Netzmacht\JavascriptBuilder\Encoder; -use Netzmacht\JavascriptBuilder\Encoder\Chain\MultipleChain; use Netzmacht\JavascriptBuilder\Encoder\ChainEncoder; use Netzmacht\JavascriptBuilder\Encoder\JavascriptEncoder; use Netzmacht\JavascriptBuilder\Encoder\MultipleObjectsEncoder; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php index b01ca2b..0c3f8c5 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php @@ -12,11 +12,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\UI; use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Leaflet\Model\PopupModel; -use Netzmacht\Contao\Leaflet\ServiceContainerTrait; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\UI\Marker; @@ -29,8 +29,6 @@ use Netzmacht\LeafletPHP\Definition\UI\Popup; */ class MarkerMapper extends AbstractMapper { - use ServiceContainerTrait; - /** * Class of the model being build. * @@ -45,6 +43,25 @@ class MarkerMapper extends AbstractMapper */ protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\UI\Marker'; + /** + * Frontend filter. + * + * @var ValueFilter + */ + protected $valueFilter; + + /** + * Construct. + * + * @param ValueFilter $valueFilter Frontend filter. + */ + public function __construct(ValueFilter $valueFilter) + { + parent::__construct(); + + $this->valueFilter = $valueFilter; + } + /** * {@inheritdoc} */ @@ -85,10 +102,7 @@ class MarkerMapper extends AbstractMapper if ($definition instanceof Marker) { if ($model->addPopup) { $popup = null; - $content = $this - ->getServiceContainer() - ->getFrontendValueFilter() - ->filter($model->popupContent); + $content = $this->valueFilter->filter($model->popupContent); if ($model->popup) { $popupModel = PopupModel::findActiveByPK($model->popup); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php index 39fb0f2..6eb04e8 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php @@ -13,11 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; use Netzmacht\Contao\Leaflet\Definition\Style; use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\PopupModel; use Netzmacht\Contao\Leaflet\Model\StyleModel; -use Netzmacht\Contao\Leaflet\ServiceContainerTrait; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\HasPopup; use Netzmacht\LeafletPHP\Definition\UI\Popup; @@ -30,8 +30,6 @@ use Netzmacht\LeafletPHP\Definition\Vector\Path; */ class AbstractVectorMapper extends AbstractTypeMapper { - use ServiceContainerTrait; - /** * Class of the model being build. * @@ -39,6 +37,25 @@ class AbstractVectorMapper extends AbstractTypeMapper */ protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\VectorModel'; + /** + * Frontend filter. + * + * @var ValueFilter + */ + protected $valueFilter; + + /** + * Construct. + * + * @param ValueFilter $valueFilter Frontend filter. + */ + public function __construct(ValueFilter $valueFilter) + { + parent::__construct(); + + $this->valueFilter = $valueFilter; + } + /** * {@inheritdoc} */ @@ -84,10 +101,7 @@ class AbstractVectorMapper extends AbstractTypeMapper ) { if ($definition instanceof HasPopup && $model->addPopup) { $popup = null; - $content = $this - ->getServiceContainer() - ->getFrontendValueFilter() - ->filter($model->popupContent); + $content = $this->valueFilter->filter($model->popupContent); if ($model->popup) { $popupModel = PopupModel::findActiveByPK($model->popup); diff --git a/src/Netzmacht/Contao/Leaflet/ServiceContainerTrait.php b/src/Netzmacht/Contao/Leaflet/ServiceContainerTrait.php deleted file mode 100644 index fddd5b5..0000000 --- a/src/Netzmacht/Contao/Leaflet/ServiceContainerTrait.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @copyright 2015 netzmacht creative David Molineus - * @license LGPL 3.0 - * @filesource - * - */ - -namespace Netzmacht\Contao\Leaflet; - -/** - * Class ServiceContainerTrait provides simple access to the service container. - * - * @package Netzmacht\Contao\Leaflet - */ -trait ServiceContainerTrait -{ - /** - * Get the service container. - * - * @return ServiceContainer - * @SuppressWarnings(PHPMD.Superglobals) - */ - protected function getServiceContainer() - { - return $GLOBALS['container']['leaflet.service-container']; - } -} diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php index 7c9bf19..35746f4 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php @@ -17,6 +17,7 @@ use Netzmacht\Contao\Leaflet\Event\InitializeDefinitionMapperEvent; use Netzmacht\Contao\Leaflet\Event\InitializeEventDispatcherEvent; use Netzmacht\Contao\Leaflet\Event\InitializeLeafletBuilderEvent; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Mapper\Mapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\LeafletPHP\Assets; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; @@ -53,14 +54,13 @@ class BootSubscriber implements EventSubscriberInterface */ public function initializeDefinitionMapper(InitializeDefinitionMapperEvent $event) { - $mapper = $event->getDefinitionMapper(); - $container = $GLOBALS['container']['leaflet.service-container']; + $mapper = $event->getDefinitionMapper(); foreach ($GLOBALS['LEAFLET_MAPPERS'] as $className) { if (is_array($className)) { - $mapper->register(new $className[0], $className[1]); + $mapper->register($this->createMapper($className[0]), $className[1]); } else { - $mapper->register(new $className($container)); + $mapper->register($this->createMapper($className)); } } } @@ -162,6 +162,11 @@ class BootSubscriber implements EventSubscriberInterface } } + /** + * Set the static flag. + * + * @return string + */ private function staticFlag() { if (\Config::get('debugMode') || TL_MODE !== 'FE') { @@ -170,4 +175,24 @@ class BootSubscriber implements EventSubscriberInterface return '|static'; } + + /** + * Create a new mapper. + * + * @param mixed $mapper The mapper class or callable factory. + * + * @return Mapper + * + * @SuppressWarnings(PHPMD.Superglobals) + */ + private function createMapper($mapper) + { + if (is_callable($mapper)) { + $container = $GLOBALS['container']['leaflet.service-container']; + + return $mapper($container); + } + + return new $mapper; + } }