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 Psr\Container\ContainerInterface
; 
  16 use Rapsys\PackBundle\Parser\TokenParser
; 
  17 use Rapsys\PackBundle\RapsysPackBundle
; 
  18 use Rapsys\PackBundle\Util\IntlUtil
; 
  19 use Rapsys\PackBundle\Util\SluggerUtil
; 
  21 use Symfony\Component\Routing\RouterInterface
; 
  22 use Symfony\Component\HttpKernel\Config\FileLocator
; 
  24 use Twig\Extension\AbstractExtension
; 
  29 class PackExtension 
extends AbstractExtension 
{ 
  33         protected array $config; 
  36          * The stream context instance 
  41          * Creates pack extension 
  45          * @link https://twig.symfony.com/doc/2.x/advanced.html 
  47          * @param ContainerInterface $container The ContainerInterface instance 
  48          * @param IntlUtil $intl The IntlUtil instance 
  49          * @param FileLocator $locator The FileLocator instance 
  50          * @param RouterInterface $router The RouterInterface instance 
  51          * @param SluggerUtil $slugger The SluggerUtil instance 
  53         public function __construct(protected ContainerInterface 
$container, protected IntlUtil 
$intl, protected FileLocator 
$locator, protected RouterInterface 
$router, protected SluggerUtil 
$slugger) { 
  55                 $this->config 
= $container->getParameter(RapsysPackBundle
::getAlias()); 
  58                 $this->ctx 
= stream_context_create($this->config
['context']); 
  62          * Returns a filter array to add to the existing list. 
  64          * @return \Twig\TwigFilter[] 
  66         public function getTokenParsers(): array { 
  68                         new TokenParser($this->container
, $this->locator
, $this->router
, $this->slugger
, $this->config
, $this->ctx
, 'css', 'stylesheet'), 
  69                         new TokenParser($this->container
, $this->locator
, $this->router
, $this->slugger
, $this->config
, $this->ctx
, 'js', 'javascript'), 
  70                         new TokenParser($this->container
, $this->locator
, $this->router
, $this->slugger
, $this->config
, $this->ctx
, 'img', 'image') 
  75          * Returns a filter array to add to the existing list. 
  77          * @return \Twig\TwigFilter[] 
  79         public function getFilters(): array { 
  81                         new \Twig\
TwigFilter('base64_decode', 'base64_decode'), 
  82                         new \Twig\
TwigFilter('base64_encode', 'base64_encode'), 
  83                         new \Twig\
TwigFilter('download', 'file_get_contents', [false, null]), 
  84                         new \Twig\
TwigFilter('hash', [$this->slugger
, 'hash']), 
  85                         new \Twig\
TwigFilter('intlcurrency', [$this->intl
, 'currency']), 
  86                         new \Twig\
TwigFilter('intldate', [$this->intl
, 'date'], ['needs_environment' => true]), 
  87                         new \Twig\
TwigFilter('intlnumber', [$this->intl
, 'number']), 
  88                         new \Twig\
TwigFilter('lcfirst', 'lcfirst'), 
  89                         new \Twig\
TwigFilter('short', [$this->slugger
, 'short']), 
  90                         new \Twig\
TwigFilter('slug', [$this->slugger
, 'slug']), 
  91                         new \Twig\
TwigFilter('ucfirst', 'ucfirst'), 
  92                         new \Twig\
TwigFilter('unshort', [$this->slugger
, 'unshort'])