]> Raphaƫl G. Git Repositories - packbundle/blob - Twig/PackExtension.php
Add default unit test
[packbundle] / Twig / PackExtension.php
1 <?php
2 // src/Rapsys/PackBundle/Twig/PackExtension.php
3 namespace Rapsys\PackBundle\Twig;
4
5 use Symfony\Component\HttpKernel\Config\FileLocator;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 class PackExtension extends \Twig_Extension {
9 public function __construct(FileLocator $fileLocator, ContainerInterface $containerInterface) {
10 //Set file locator
11 $this->fileLocator = $fileLocator;
12 //Set container interface
13 $this->containerInterface = $containerInterface;
14
15 //Set default prefix
16 $this->prefix = '@RapsysPackBundle/Resources/public/';
17
18 //Set default coutput
19 $this->coutput = 'css/*.pack.css';
20 //Set default joutput
21 $this->joutput = 'js/*.pack.js';
22 //Set default ioutput
23 $this->ioutput = 'img/*.pack.jpg';
24
25 //Set default cfilter
26 $this->cfilter = array('CPackFilter');
27 //Set default jfilter
28 $this->jfilter = array('JPackFilter');
29 //Set default ifilter
30 $this->ifilter = array('IPackFilter');
31
32 //Load configuration
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)) {
37 $this->$k = $v;
38 }
39 }
40 }
41 }
42
43 //Fix prefix
44 $this->prefix = $this->fileLocator->locate($this->prefix);
45 }
46
47 public function getTokenParsers() {
48 return array(
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),
52 );
53 }
54 }