mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 05:43:10 +02:00
feat(core): add parser twig extension #262
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user