|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony framework. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * This source file is subject to the MIT license that is bundled |
|
9 * with this source code in the file LICENSE. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Bundle\AsseticBundle\Twig; |
|
13 |
|
14 use Assetic\Asset\AssetInterface; |
|
15 use Assetic\Extension\Twig\AsseticNode as BaseAsseticNode; |
|
16 |
|
17 /** |
|
18 * Assetic node. |
|
19 * |
|
20 * @author Kris Wallsmith <kris@symfony.com> |
|
21 */ |
|
22 class AsseticNode extends BaseAsseticNode |
|
23 { |
|
24 protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name) |
|
25 { |
|
26 $compiler |
|
27 ->raw('isset($context[\'assetic\'][\'use_controller\']) && $context[\'assetic\'][\'use_controller\'] ? ') |
|
28 ->subcompile($this->getPathFunction($name)) |
|
29 ->raw(' : ') |
|
30 ->subcompile($this->getAssetFunction($asset->getTargetPath())) |
|
31 ; |
|
32 } |
|
33 |
|
34 private function getPathFunction($name) |
|
35 { |
|
36 return new \Twig_Node_Expression_Function( |
|
37 new \Twig_Node_Expression_Name('path', $this->getLine()), |
|
38 new \Twig_Node(array(new \Twig_Node_Expression_Constant('_assetic_'.$name, $this->getLine()))), |
|
39 $this->getLine() |
|
40 ); |
|
41 } |
|
42 |
|
43 private function getAssetFunction($path) |
|
44 { |
|
45 $arguments = array(new \Twig_Node_Expression_Constant($path, $this->getLine())); |
|
46 |
|
47 if ($this->hasAttribute('package')) { |
|
48 $arguments[] = new \Twig_Node_Expression_Constant($this->getAttribute('package'), $this->getLine()); |
|
49 } |
|
50 |
|
51 return new \Twig_Node_Expression_Function( |
|
52 new \Twig_Node_Expression_Name('asset', $this->getLine()), |
|
53 new \Twig_Node($arguments), |
|
54 $this->getLine() |
|
55 ); |
|
56 } |
|
57 } |