]> Raphaël G. Git Repositories - packbundle/blob - Extension/PackExtension.php
Rename pack bundle alias
[packbundle] / Extension / PackExtension.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\PackBundle\Extension;
13
14 use Symfony\Component\Asset\PackageInterface;
15 use Symfony\Component\HttpKernel\Config\FileLocator;
16
17 use Twig\Extension\AbstractExtension;
18
19 use Rapsys\PackBundle\Parser\TokenParser;
20 use Rapsys\PackBundle\RapsysPackBundle;
21 use Rapsys\PackBundle\Util\IntlUtil;
22 use Rapsys\PackBundle\Util\SluggerUtil;
23
24 /**
25 * {@inheritdoc}
26 */
27 class PackExtension extends AbstractExtension {
28 /**
29 * @link https://twig.symfony.com/doc/2.x/advanced.html
30 *
31 * {@inheritdoc}
32 */
33 public function __construct(protected IntlUtil $intl, protected FileLocator $locator, protected PackageInterface $package, protected SluggerUtil $slugger, protected array $parameters) {
34 }
35
36 /**
37 * Returns a filter array to add to the existing list.
38 *
39 * @return \Twig\TwigFilter[]
40 */
41 public function getTokenParsers(): array {
42 return [
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'])
46 ];
47 }
48
49 /**
50 * Returns a filter array to add to the existing list.
51 *
52 * @return \Twig\TwigFilter[]
53 */
54 public function getFilters(): array {
55 return [
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')
68 ];
69 }
70 }