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 Rapsys\PackBundle\Parser\TokenParser
;
15 use Rapsys\PackBundle\RapsysPackBundle
;
16 use Rapsys\PackBundle\Util\IntlUtil
;
17 use Rapsys\PackBundle\Util\SluggerUtil
;
19 use Symfony\Component\Asset\PackageInterface
;
20 use Symfony\Component\HttpKernel\Config\FileLocator
;
22 use Twig\Extension\AbstractExtension
;
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('base64_decode', 'base64_decode'),
57 new \Twig\
TwigFilter('base64_encode', 'base64_encode'),
58 new \Twig\
TwigFilter('download', 'file_get_contents', [false, null]),
59 new \Twig\
TwigFilter('hash', [$this->slugger
, 'hash']),
60 new \Twig\
TwigFilter('intlcurrency', [$this->intl
, 'currency']),
61 new \Twig\
TwigFilter('intldate', [$this->intl
, 'date'], ['needs_environment' => true]),
62 new \Twig\
TwigFilter('intlnumber', [$this->intl
, 'number']),
63 new \Twig\
TwigFilter('intlsize', [$this->intl
, 'size']),
64 new \Twig\
TwigFilter('lcfirst', 'lcfirst'),
65 new \Twig\
TwigFilter('short', [$this->slugger
, 'short']),
66 new \Twig\
TwigFilter('slug', [$this->slugger
, 'slug']),
67 new \Twig\
TwigFilter('ucfirst', 'ucfirst'),
68 new \Twig\
TwigFilter('unshort', [$this->slugger
, 'unshort'])