Fix api inconsistency for Contao 3.5 (See #37).

This commit is contained in:
David Molineus
2015-07-22 13:56:37 +02:00
parent ff8cda1371
commit 3c983e86bc
3 changed files with 49 additions and 9 deletions

View File

@@ -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) {

View File

@@ -0,0 +1,40 @@
<?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;
/**
* 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);
}
}

View File

@@ -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);
}
}