]> Raphaël G. Git Repositories - packbundle/blob - Extension/PackExtension.php
Move package and route configurations in Resources/config/ to config/
[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 Rapsys\PackBundle\Parser\TokenParser;
15 use Rapsys\PackBundle\RapsysPackBundle;
16 use Rapsys\PackBundle\Util\IntlUtil;
17 use Rapsys\PackBundle\Util\SluggerUtil;
18
19 use Symfony\Component\Asset\PackageInterface;
20 use Symfony\Component\HttpKernel\Config\FileLocator;
21
22 use Twig\Extension\AbstractExtension;
23
24 /**
25 * {@inheritdoc}
26 */
27 class PackExtension extends AbstractExtension {
28 /**
29 * {@inheritdoc}
30 *
31 * @link https://twig.symfony.com/doc/2.x/advanced.html
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('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'])
69 ];
70 }
71 }