]> Raphaƫl G. Git Repositories - packbundle/blob - Twig/PackExtension.php
3b4aa072fa90711abc2114376207ba527e1f0f37
[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 #, $prefix = '@RapsysPackBundle/Resources/public/', $cpack = '/usr/local/bin/cpack', $jpack = '/usr/local/bin/jpack'
10 #$this->kernel = $kernel;
11 public function __construct(FileLocator $fileLocator, ContainerInterface $containerInterface) {
12 //Set file locator
13 $this->fileLocator = $fileLocator;
14 //Set container interface
15 $this->containerInterface = $containerInterface;
16
17 //Set default prefix
18 $this->prefix = '@RapsysPackBundle/Resources/public/';
19
20 //Set default coutput
21 $this->coutput = 'css/*.pack.css';
22 //Set default joutput
23 $this->joutput = 'js/*.pack.js';
24
25 //Set default cpack
26 $this->cpack = '/usr/local/bin/cpack';
27 //Set default jpack
28 $this->jpack = '/usr/local/bin/jpack';
29
30 //Load configuration
31 if ($containerInterface->hasParameter('rapsys_pack')) {
32 foreach($containerInterface->getParameter('rapsys_pack') as $k => $v) {
33 if (isset($this->$k)) {
34 $this->$k = $v;
35 }
36 }
37 }
38
39 //Fix prefix
40 $this->prefix = $this->fileLocator->locate($this->prefix);
41 }
42
43 public function getTokenParsers() {
44 return array(
45 new PackTokenParser($this->fileLocator, $this->containerInterface, $this->prefix, 'stylesheets', $this->coutput, $this->cpack),
46 new PackTokenParser($this->fileLocator, $this->containerInterface, $this->prefix, 'javascripts', $this->joutput, $this->jpack),
47 #new PackTokenParser($this->fileLocator, $this->containerInterface, $this->prefix, 'image', '*.pack.{tld}'),
48 );
49 }
50 }