diff --git a/module/config/services.php b/module/config/services.php index e5670a8..e0da136 100644 --- a/module/config/services.php +++ b/module/config/services.php @@ -11,7 +11,7 @@ use Netzmacht\Contao\Leaflet\Boot; use Netzmacht\Contao\Leaflet\ContaoAssets; -use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi; +use Netzmacht\Contao\Leaflet\Frontend\Helper\InsertTagReplacer; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\MapService; @@ -114,7 +114,7 @@ $container['leaflet.definition.builder'] = $container->share(function($container }); $container['leaflet.frontend.value-filter'] = $container->share(function() { - return new ValueFilter(new FrontendApi()); + return new ValueFilter(new InsertTagReplacer()); }); $container['leaflet.service-container'] = $container->share(function($container) { diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/Helper/InsertTagReplacer.php b/src/Netzmacht/Contao/Leaflet/Frontend/Helper/InsertTagReplacer.php new file mode 100644 index 0000000..a55ccf2 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Frontend/Helper/InsertTagReplacer.php @@ -0,0 +1,40 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Frontend\Helper; + +/** + * This class is a helper to replace insert tags. + * + * @package Netzmacht\Contao\Leaflet\Frontend\Helper + */ +class InsertTagReplacer +{ + /** + * Replace insert tags with their values. + * + * @param string $buffer The text with the tags to be replaced. + * @param boolean $cache If false, non-cacheable tags will be replaced. + * + * @return string + */ + public function replace($buffer, $cache = true) + { + if (version_compare(VERSION, '3.5', '<')) { + $frontendApi = new FrontendApi(); + + return $frontendApi->replaceInsertTags($buffer, $cache); + } + + $replacer = new \InsertTags(); + return $replacer->replace($buffer, $cache); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php b/src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php index 11a855b..8975e87 100644 --- a/src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php +++ b/src/Netzmacht/Contao/Leaflet/Frontend/ValueFilter.php @@ -11,7 +11,7 @@ namespace Netzmacht\Contao\Leaflet\Frontend; -use Netzmacht\Contao\Leaflet\Frontend\Helper\FrontendApi; +use Netzmacht\Contao\Leaflet\Frontend\Helper\InsertTagReplacer; /** * Class ValueFilter is a service class which can be used to filter values before passing them to an definition object. @@ -23,18 +23,18 @@ class ValueFilter /** * The frontend api of Contao. * - * @var FrontendApi + * @var InsertTagReplacer */ - private $api; + private $insertTagReplacer; /** * Construct. * - * @param FrontendApi $api The frontend api of Contao. + * @param InsertTagReplacer $replacer The insert tag replacer. */ - public function __construct($api) + public function __construct($replacer) { - $this->api = $api; + $this->insertTagReplacer = $replacer; } /** @@ -49,6 +49,6 @@ class ValueFilter */ public function filter($value) { - return $this->api->replaceInsertTags($value); + return $this->insertTagReplacer->replace($value); } }