Created
July 30, 2019 09:34
-
-
Save imiroslavov/3034fee701495c73de57a772491bc7a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Twig\Extension; | |
use Twig\Extension\AbstractExtension; | |
use Twig\TwigFilter; | |
/** | |
* Class JsonDecodeTwigExtension. | |
*/ | |
class JsonDecodeTwigExtension extends AbstractExtension | |
{ | |
/** | |
* @return array | |
*/ | |
public function getFilters() | |
{ | |
return [ | |
new TwigFilter('json_decode', [$this, 'jsonDecode']), | |
]; | |
} | |
/** | |
* @param string $input | |
* @param bool $assoc | |
* | |
* @return string | |
*/ | |
public function jsonDecode($input, $assoc = false) | |
{ | |
return json_decode($input, $assoc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment