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:
@@ -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));
|
||||
|
||||
|
45
flextype/twig/ParserTwigExtension.php
Normal file
45
flextype/twig/ParserTwigExtension.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user