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

Flextype: JsonParserTwigExtension - added

This commit is contained in:
Awilum
2019-04-25 16:07:53 +03:00
parent b92979a57e
commit 4bbd080b44

View File

@@ -0,0 +1,39 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @link http://romanenko.digital
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
class JsonParserTwigExtension extends \Twig_Extension
{
/**
* Callback for twig.
*
* @return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction('json_parser_decode', array($this, 'json_parser_decode')),
new \Twig_SimpleFunction('json_parser_encode', array($this, 'json_parser_encode'))
];
}
public function encode($input, int $encode_options = 0, int $encode_depth = 512) : string
{
return JsonParser::encode($input, $encode_options, $encode_depth);
}
public function decode(string $input, bool $decode_assoc = true, int $decode_depth = 512, int $decode_options = 0)
{
return JsonParser::decode($input, $decode_assoc, $decode_depth, $decode_options);
}
}