1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-24 13:52:56 +02:00

feat(core): add parser twig extension #262

This commit is contained in:
Awilum
2019-10-14 20:19:13 +03:00
parent 2d67b49bd0
commit f0b338cf51
2 changed files with 48 additions and 0 deletions

View File

@@ -247,6 +247,9 @@ $flextype['view'] = static function ($container) {
// Add Yaml Twig Extension
$view->addExtension(new YamlTwigExtension());
// Add Parser Twig Extension
$view->addExtension(new ParserTwigExtension());
// Add Markdown Twig Extension
$view->addExtension(new MarkdownTwigExtension($container));

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/**
* Flextype (http://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype;
use Twig_Extension;
use Twig_SimpleFunction;
class ParserTwigExtension extends Twig_Extension
{
/**
* Returns a list of functions to add to the existing list.
*
* @return array
*/
public function getFunctions() : array
{
return [
new Twig_SimpleFunction('parser_decode', [$this, 'decode']),
new Twig_SimpleFunction('parser_encode', [$this, 'encode']),
];
}
/**
* Encode YAML
*/
public function encode($input, string $parser)
{
return Parser::encode($input, $parser);
}
/**
* Decode YAML
*/
public function decode(string $input, string $parser)
{
return Parser::decode($input, $parser);
}
}