Use the framework.

This commit is contained in:
David Molineus
2017-10-11 17:57:48 +02:00
parent 56a68175fe
commit a8491bdc4b
2 changed files with 44 additions and 2 deletions

View File

@@ -39,6 +39,8 @@ services:
netzmacht.contao_leaflet.frontend.value_filter:
class: Netzmacht\Contao\Leaflet\Frontend\ValueFilter
arguments:
- '@contao.framework'
netzmacht.contao_leaflet.map.assets:
class: Netzmacht\Contao\Leaflet\Encoder\ContaoAssets

View File

@@ -12,7 +12,8 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFrameworkInterface as ContaoFramework;
use Contao\InsertTags;
/**
* Class ValueFilter is a service class which can be used to filter values before passing them to an definition object.
@@ -21,6 +22,45 @@ use Contao\Controller;
*/
class ValueFilter
{
/**
* Contao framework.
*
* @var ContaoFramework
*/
private $framework;
/**
* Insert tags.
*
* @var InsertTags
*/
private $replacer;
/**
* ValueFilter constructor.
*
* @param ContaoFramework $framework Contao framework.
*/
public function __construct(ContaoFramework $framework)
{
$this->framework = $framework;
}
/**
* Get the replacer.
*
* @return InsertTags
*/
private function getReplacer(): InsertTags
{
if ($this->replacer === null) {
$this->framework->initialize();
$this->replacer = $this->framework->createInstance(InsertTags::class);
}
return $this->replacer;
}
/**
* Filter a value so it can be passed to the frontend.
*
@@ -33,6 +73,6 @@ class ValueFilter
*/
public function filter($value)
{
return Controller::replaceInsertTags($value);
return $this->getReplacer()->replace($value);
}
}