From a1dea2b787bbdc6e10f06fc49092dd6a11e21396 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 15 Oct 2019 17:14:10 +0300 Subject: [PATCH] feat(core): add parser twig extension #262 --- flextype/twig/ParserTwigExtension.php | 34 ++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/flextype/twig/ParserTwigExtension.php b/flextype/twig/ParserTwigExtension.php index ecbf15d9..f2a31cef 100644 --- a/flextype/twig/ParserTwigExtension.php +++ b/flextype/twig/ParserTwigExtension.php @@ -14,6 +14,19 @@ use Twig_SimpleFunction; class ParserTwigExtension extends Twig_Extension { + /** + * Flextype Dependency Container + */ + private $flextype; + + /** + * Constructor + */ + public function __construct($flextype) + { + $this->flextype = $flextype; + } + /** * Returns a list of functions to add to the existing list. * @@ -24,22 +37,31 @@ class ParserTwigExtension extends Twig_Extension return [ new Twig_SimpleFunction('parser_decode', [$this, 'decode']), new Twig_SimpleFunction('parser_encode', [$this, 'encode']), + new Twig_SimpleFunction('parser_get_info', [$this, 'getParserInfo']), ]; } /** - * Encode YAML + * Get Parser Info */ - public function encode($input, string $parser) + public function getParserInfo(string $parser) : array { - return Parser::encode($input, $parser); + return $this->flextype['parser']->getParserInfo($parser); } /** - * Decode YAML + * Encode */ - public function decode(string $input, string $parser) + public function encode($input, string $parser) { - return Parser::decode($input, $parser); + return $this->flextype['parser']->encode($input, $parser); + } + + /** + * Decode + */ + public function decode(string $input, string $parser, bool $cache) + { + return $this->flextype['parser']->decode($input, $parser, $cache); } }