1 | <?php |
||
9 | class AssetsTokenParser extends \Twig_TokenParser |
||
10 | { |
||
11 | |||
12 | protected $type; |
||
13 | private $values = array(); |
||
14 | private $end = false; |
||
15 | |||
16 | /** |
||
17 | * @param string $type |
||
18 | */ |
||
19 | 1 | public function __construct($type = 'js') |
|
23 | |||
24 | /** |
||
25 | * Método que parsea los nodos de la plantilla |
||
26 | * @param \Twig_Token $token |
||
27 | * @return AssetsNode |
||
28 | * @throws \Twig_Error_Syntax |
||
29 | * @throws \Twig_Error_Loader |
||
30 | */ |
||
31 | 2 | public function parse(\Twig_Token $token) |
|
32 | { |
||
33 | 2 | $hash = substr(md5($this->parser->getStream()->getSourceContext()->getPath()), 0, 8); |
|
34 | 2 | $name = $token->getValue(); |
|
35 | 2 | $this->extractTemplateNodes(); |
|
36 | 1 | $node = $this->findTemplateNode(); |
|
37 | 1 | return new AssetsNode($name, array("node" => $node, "hash" => $hash), $token->getLine(), $this->getTag(), $this->type); |
|
|
|||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Método que devuelve el tag a buscar en la plantilla |
||
42 | * @return string |
||
43 | */ |
||
44 | 2 | public function getTag() |
|
45 | { |
||
46 | 2 | switch ($this->type) { |
|
47 | default: |
||
48 | case 'js': |
||
49 | 2 | $return = 'scripts'; |
|
50 | 2 | break; |
|
51 | case 'css': |
||
52 | 2 | $return = 'styles'; |
|
53 | 2 | break; |
|
54 | } |
||
55 | 2 | return $return; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Método que revisa cada l�nea de la plantilla |
||
60 | * @param \Twig_TokenStream $stream |
||
61 | * @return \Twig_TokenStream |
||
62 | */ |
||
63 | 1 | protected function checkTemplateLine(\Twig_TokenStream $stream) |
|
80 | |||
81 | /** |
||
82 | * Método que procesa cada l�nea de la plantilla para extraer los nodos |
||
83 | * @throws \Twig_Error_Syntax |
||
84 | */ |
||
85 | 2 | protected function extractTemplateNodes() |
|
96 | |||
97 | /** |
||
98 | * Método que busca el nodo a parsear |
||
99 | * @return \Twig_Node_Expression|null |
||
100 | */ |
||
101 | 1 | protected function findTemplateNode() |
|
113 | |||
114 | /** |
||
115 | * Método que extrae el valor del token |
||
116 | * @param \Twig_Node_Expression|\Twig_Node_Expression_Conditional|null $node |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 1 | protected function getTmpAttribute($node = null) |
|
129 | |||
130 | /** |
||
131 | * Método |
||
132 | * @param \Twig_Node_Expression|\Twig_Node_Expression_Conditional|null $node |
||
133 | * @param \Twig_Node_Expression|\Twig_Node_Expression_Conditional|null $value |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 1 | protected function extractTmpAttribute($node = null, $value = null) |
|
149 | } |
||
150 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.