Replace insert tags and masked entities. (Fix #17)

This commit is contained in:
David Molineus
2015-01-22 12:24:22 +01:00
parent b65bcbff9f
commit 9dfb6698cf
7 changed files with 202 additions and 2 deletions

View File

@@ -10,8 +10,11 @@
*/
use Netzmacht\Contao\Leaflet\Boot;
use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\MapService;
use Netzmacht\Contao\Leaflet\ServiceContainer;
use Netzmacht\JavascriptBuilder\Builder;
use Netzmacht\JavascriptBuilder\Encoder;
use Netzmacht\JavascriptBuilder\Encoder\Chain\MultipleChain;
@@ -100,3 +103,11 @@ $container['leaflet.definition.builder'] = $container->share(function($container
return $boot->initializeLeafletBuilder($leaflet);
});
$container['leaflet.frontend.value-filter'] = $container->share(function() {
return new ValueFilter(new FrontendApi());
});
$container['leaflet.service-container'] = $container->share(function($container) {
return new ServiceContainer($container);
});

View File

@@ -0,0 +1,28 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Frontend\Helper;
/**
* Class FrontendApi provides access to the frontend api of contao.
*
* @package Netzmacht\Contao\Leaflet\Frontend\Helper
*/
class FrontendApi extends \Frontend
{
/**
* {@inheritdoc}
*/
public function replaceInsertTags($strBuffer, $blnCache = true)
{
return parent::replaceInsertTags($strBuffer, $blnCache);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Frontend;
use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi;
/**
* Class ValueFilter is a service class which can be used to filter values before passing them to an definition object.
*
* @package Netzmacht\Contao\Leaflet\Frontend
*/
class ValueFilter
{
/**
* The frontend api of Contao.
*
* @var FrontendApi
*/
private $api;
/**
* Construct.
*
* @param FrontendApi $api The frontend api of Contao.
*/
public function __construct($api)
{
$this->api = $api;
}
/**
* Filter a value so it can be passed to the frontend.
*
* The idea behind this extra method is that we just have to change one place if anything else than the
* insert tags has to be replaced.
*
* @param string $value The given value
*
* @return string
*/
public function filter($value)
{
return $this->api->replaceInsertTags($value);
}
}

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\UI;
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
@@ -26,6 +27,8 @@ use Netzmacht\LeafletPHP\Definition\UI\Marker;
*/
class MarkerMapper extends AbstractMapper
{
use ServiceContainerTrait;
/**
* Class of the model being build.
*
@@ -79,7 +82,12 @@ class MarkerMapper extends AbstractMapper
) {
if ($definition instanceof Marker) {
if ($model->addPopup) {
$definition->bindPopup($model->popupContent);
$content = $this
->getServiceContainer()
->getFrontendValueFilter()
->filter($model->popupContent);
$definition->bindPopup($content);
}
if ($model->customIcon) {

View File

@@ -15,6 +15,7 @@ use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\StyleModel;
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\HasPopup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
@@ -27,6 +28,8 @@ use Netzmacht\LeafletPHP\Definition\Vector\Path;
*/
class AbstractVectorMapper extends AbstractTypeMapper
{
use ServiceContainerTrait;
/**
* Class of the model being build.
*
@@ -59,7 +62,12 @@ class AbstractVectorMapper extends AbstractTypeMapper
}
if ($definition instanceof HasPopup && $model->addPopup) {
$definition->bindPopup($model->popupContent);
$content = $this
->getServiceContainer()
->getFrontendValueFilter()
->filter($model->popupContent);
$definition->bindPopup($content);
}
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
/**
* Class ServiceContainer
*
* @package Netzmacht\Contao\Leaflet
*/
class ServiceContainer
{
/**
* The global service container.
*
* @var \Pimple
*/
private $container;
/**
* Construct.
*
* @param \Pimple $container The global service container.
*/
public function __construct(\Pimple $container)
{
$this->container = $container;
}
/**
* Get the value filter service.
*
* @return ValueFilter
*/
public function getFrontendValueFilter()
{
return $this->getService('leaflet.frontend.value-filter');
}
/**
* Get a service from the container.
*
* @param string $name The service name.
*
* @return mixed
*/
public function getService($name)
{
return $this->container[$name];
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @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
*/
protected function getServiceContainer()
{
return $GLOBALS['container']['leaflet.service-container'];
}
}