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\DependencyInjection\ContainerInterface
;
16 use Symfony\Component\HttpKernel\Config\FileLocator
;
17 use Twig\Extension\AbstractExtension
;
19 use Rapsys\PackBundle\Util\SluggerUtil
;
20 use Rapsys\PackBundle\Parser\TokenParser
;
25 class PackExtension
extends AbstractExtension
{
38 //The slugger instance
45 * @link https://twig.symfony.com/doc/2.x/advanced.html
49 public function __construct(FileLocator
$locator, ContainerInterface
$container, PackageInterface
$package, SluggerUtil
$slugger) {
51 $this->locator
= $locator;
54 $this->slugger
= $slugger;
57 $this->package
= $package;
59 //Retrieve bundle config
60 if ($parameters = $container->getParameter($this->getAlias())) {
61 //Set config, output and filters arrays
62 foreach(['config', 'output', 'filters'] as $k) {
63 $this->$k = $parameters[$k];
69 * Returns a list of filters to add to the existing list.
71 * @return \Twig\TwigFilter[]
73 public function getTokenParsers(): array {
75 new TokenParser($this->locator
, $this->package
, $this->config
, 'stylesheet', $this->output
['css'], $this->filters
['css']),
76 new TokenParser($this->locator
, $this->package
, $this->config
, 'javascript', $this->output
['js'], $this->filters
['js']),
77 new TokenParser($this->locator
, $this->package
, $this->config
, 'image', $this->output
['img'], $this->filters
['img'])
82 * Returns a list of filters to add to the existing list.
84 * @return \Twig\TwigFilter[]
86 public function getFilters(): array {
88 new \Twig\
TwigFilter('hash', [$this->slugger
, 'hash']),
89 new \Twig\
TwigFilter('unshort', [$this->slugger
, 'unshort']),
90 new \Twig\
TwigFilter('short', [$this->slugger
, 'short'])
97 public function getAlias(): string {