Skip to content

Instantly share code, notes, and snippets.

@imiroslavov
Created July 30, 2019 09:34
Show Gist options
  • Save imiroslavov/3034fee701495c73de57a772491bc7a4 to your computer and use it in GitHub Desktop.
Save imiroslavov/3034fee701495c73de57a772491bc7a4 to your computer and use it in GitHub Desktop.
<?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