1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys PackBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\PackBundle\Extension
;
14 use Symfony\Component\Asset\PackageInterface
;
15 use Symfony\Component\HttpKernel\Config\FileLocator
;
17 use Twig\Extension\AbstractExtension
;
19 use Rapsys\PackBundle\Parser\TokenParser
;
20 use Rapsys\PackBundle\RapsysPackBundle
;
21 use Rapsys\PackBundle\Util\IntlUtil
;
22 use Rapsys\PackBundle\Util\SluggerUtil
;
27 class PackExtension
extends AbstractExtension
{
31 * @link https://twig.symfony.com/doc/2.x/advanced.html
33 public function __construct(protected IntlUtil
$intl, protected FileLocator
$locator, protected PackageInterface
$package, protected SluggerUtil
$slugger, protected array $parameters) {
37 * Returns a filter array to add to the existing list.
39 * @return \Twig\TwigFilter[]
41 public function getTokenParsers(): array {
43 new TokenParser($this->locator
, $this->package
, $this->parameters
['token'], 'stylesheet', $this->parameters
['output']['css'], $this->parameters
['filters']['css']),
44 new TokenParser($this->locator
, $this->package
, $this->parameters
['token'], 'javascript', $this->parameters
['output']['js'], $this->parameters
['filters']['js']),
45 new TokenParser($this->locator
, $this->package
, $this->parameters
['token'], 'image', $this->parameters
['output']['img'], $this->parameters
['filters']['img'])
50 * Returns a filter array to add to the existing list.
52 * @return \Twig\TwigFilter[]
54 public function getFilters(): array {
56 new \Twig\
TwigFilter('lcfirst', 'lcfirst'),
57 new \Twig\
TwigFilter('ucfirst', 'ucfirst'),
58 new \Twig\
TwigFilter('hash', [$this->slugger
, 'hash']),
59 new \Twig\
TwigFilter('unshort', [$this->slugger
, 'unshort']),
60 new \Twig\
TwigFilter('short', [$this->slugger
, 'short']),
61 new \Twig\
TwigFilter('slug', [$this->slugger
, 'slug']),
62 new \Twig\
TwigFilter('intldate', [$this->intl
, 'date'], ['needs_environment' => true]),
63 new \Twig\
TwigFilter('intlnumber', [$this->intl
, 'number']),
64 new \Twig\
TwigFilter('intlcurrency', [$this->intl
, 'currency']),
65 new \Twig\
TwigFilter('download', 'file_get_contents', [false, null]),
66 new \Twig\
TwigFilter('base64_encode', 'base64_encode'),
67 new \Twig\
TwigFilter('base64_decode', 'base64_decode')