mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 13:52:56 +02:00
Flextype Core: YamlTwigExtension added. #186
This commit is contained in:
@@ -237,6 +237,9 @@ $flextype['view'] = static function ($container) {
|
||||
// Add Json Twig Extension
|
||||
$view->addExtension(new JsonTwigExtension());
|
||||
|
||||
// Add Yaml Twig Extension
|
||||
$view->addExtension(new YamlTwigExtension());
|
||||
|
||||
// Add Markdown Twig Extension
|
||||
$view->addExtension(new MarkdownTwigExtension($container));
|
||||
|
||||
|
45
flextype/twig/YamlTwigExtension.php
Normal file
45
flextype/twig/YamlTwigExtension.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 YamlTwigExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions() : array
|
||||
{
|
||||
return [
|
||||
new Twig_SimpleFunction('yaml_decode', [$this, 'decode']),
|
||||
new Twig_SimpleFunction('yaml_encode', [$this, 'encode']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode YAML
|
||||
*/
|
||||
public function encode($input, int $inline = 5, int $indent = 2, int $flags = 16) : string
|
||||
{
|
||||
return YamlParser::encode($input, $inline, $indent, $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode YAML
|
||||
*/
|
||||
public function decode(string $input, int $flags = 0)
|
||||
{
|
||||
return YamlParser::decode($input, $flags);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user