22 lines
475 B
PHP
22 lines
475 B
PHP
<?php
|
|
|
|
namespace App\Libraries\Twig;
|
|
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\TwigFilter;
|
|
|
|
class TwigJsonDecodeExtension extends AbstractExtension
|
|
{
|
|
public function getFilters(): array
|
|
{
|
|
return [
|
|
new TwigFilter('json_decode', [$this, 'jsonDecode']),
|
|
];
|
|
}
|
|
|
|
public function jsonDecode(string $json, bool $assoc = true, int $depth = 512, int $flags = 0)
|
|
{
|
|
return json_decode($json, $assoc, $depth, $flags);
|
|
}
|
|
}
|