]> Raphaƫl G. Git Repositories - packbundle/blob - Twig/PackExtension.php
Move the configuration in rapsys_pack key
[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 use Symfony\Component\Asset\Packages;
8
9 class PackExtension extends \Twig_Extension {
10 //The config
11 private $config;
12
13 //The output
14 private $output;
15
16 //The filter
17 private $filters;
18
19 public function __construct(FileLocator $fileLocator, ContainerInterface $containerInterface, Packages $assetsPackages) {
20 //Set file locator
21 $this->fileLocator = $fileLocator;
22 //Set container interface
23 $this->containerInterface = $containerInterface;
24 //Set assets packages
25 $this->assetsPackages = $assetsPackages;
26
27 //Retrieve bundle config
28 if ($parameters = $containerInterface->getParameter($this->getAlias())) {
29 foreach($parameters as $k => $v) {
30 $this->$k = $v;
31 }
32 }
33 }
34
35 public function getTokenParsers() {
36 return array(
37 new PackTokenParser($this->fileLocator, $this->assetsPackages, $this->config, 'stylesheet', $this->output['css'], $this->filters['css']),
38 new PackTokenParser($this->fileLocator, $this->assetsPackages, $this->config, 'javascript', $this->output['js'], $this->filters['js']),
39 new PackTokenParser($this->fileLocator, $this->assetsPackages, $this->config, 'image', $this->output['img'], $this->filters['img'])
40 );
41 }
42
43 /**
44 * {@inheritdoc}
45 */
46 public function getAlias() {
47 return 'rapsys_pack';
48 }
49 }