]> Raphaƫl G. Git Repositories - packbundle/blob - Twig/PackExtension.php
e441a47000e39bc494b57849df911a8b36c31681
[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
23 //Set default cpack
24 $this->cpack = '/usr/local/bin/cpack';
25 //Set default jpack
26 $this->jpack = '/usr/local/bin/jpack';
27
28 //Load configuration
29 if ($containerInterface->hasParameter('rapsys_pack')) {
30 if ($parameters = $containerInterface->getParameter('rapsys_pack')) {
31 foreach($parameters as $k => $v) {
32 if (isset($this->$k)) {
33 $this->$k = $v;
34 }
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 }