2 // src/Rapsys/PackBundle/Twig/PackExtension.php
3 namespace Rapsys\PackBundle\Twig
;
5 use Symfony\Component\HttpKernel\Config\FileLocator
;
6 use Symfony\Component\DependencyInjection\ContainerInterface
;
8 class PackExtension
extends \Twig_Extension
{
9 public function __construct(FileLocator
$fileLocator, ContainerInterface
$containerInterface) {
11 $this->fileLocator
= $fileLocator;
12 //Set container interface
13 $this->containerInterface
= $containerInterface;
16 $this->prefix
= '@RapsysPackBundle/Resources/public/';
19 $this->coutput
= 'css/*.pack.css';
21 $this->joutput
= 'js/*.pack.js';
23 $this->ioutput
= 'img/*.pack.jpg';
26 $this->cfilter
= array('CPackFilter');
28 $this->jfilter
= array('JPackFilter');
30 $this->ifilter
= array('IPackFilter');
33 if ($containerInterface->hasParameter('rapsys_pack')) {
34 if ($parameters = $containerInterface->getParameter('rapsys_pack')) {
35 foreach($parameters as $k => $v) {
36 if (isset($this->$k) && !empty($v)) {
44 $this->prefix
= $this->fileLocator
->locate($this->prefix
);
47 public function getTokenParsers() {
49 new PackTokenParser($this->fileLocator
, $this->containerInterface
, $this->prefix
, 'stylesheet', $this->coutput
, $this->cfilter
),
50 new PackTokenParser($this->fileLocator
, $this->containerInterface
, $this->prefix
, 'javascript', $this->joutput
, $this->jfilter
),
51 new PackTokenParser($this->fileLocator
, $this->containerInterface
, $this->prefix
, 'image', $this->ioutput
, $this->ifilter
),