From a8491bdc4bbab455c5d8a8ae8d51a9b688720dc9 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 11 Oct 2017 17:57:48 +0200 Subject: [PATCH] Use the framework. --- src/Bundle/Resources/config/services.yml | 2 ++ src/Frontend/ValueFilter.php | 44 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Bundle/Resources/config/services.yml b/src/Bundle/Resources/config/services.yml index e85b22a..5fdad99 100644 --- a/src/Bundle/Resources/config/services.yml +++ b/src/Bundle/Resources/config/services.yml @@ -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 diff --git a/src/Frontend/ValueFilter.php b/src/Frontend/ValueFilter.php index 66c2c60..7efe103 100644 --- a/src/Frontend/ValueFilter.php +++ b/src/Frontend/ValueFilter.php @@ -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); } }