Ejemplo n.º 1
0
 public function enterNode(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env)
 {
     if ($node instanceof Apishka_Templater_Node_Expression_GetAttr) {
         $node->setAttribute('disable_c_ext', true);
     }
     return $node;
 }
Ejemplo n.º 2
0
 /**
  * Optimizes "for" tag by removing the "loop" variable creation whenever possible.
  *
  * @param Apishka_Templater_Node        $node A Node
  * @param Apishka_Templater_Environment $env  The current Twig environment
  */
 private function enterOptimizeFor(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env)
 {
     if ($node instanceof Apishka_Templater_Node_For) {
         // disable the loop variable by default
         $node->setAttribute('with_loop', false);
         array_unshift($this->loops, $node);
         array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name'));
         array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name'));
     } elseif (!$this->loops) {
         // we are outside a loop
         return;
     } elseif ($node instanceof Apishka_Templater_Node_Expression_Name && 'loop' === $node->getAttribute('name')) {
         $node->setAttribute('always_defined', true);
         $this->addLoopToCurrent();
     } elseif ($node instanceof Apishka_Templater_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) {
         $node->setAttribute('always_defined', true);
     } elseif ($node instanceof Apishka_Templater_Node_BlockReference || $node instanceof Apishka_Templater_Node_Expression_BlockReference) {
         $this->addLoopToCurrent();
     } elseif ($node instanceof Apishka_Templater_Node_Expression_Function && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value'))) {
         $this->addLoopToAll();
     } elseif ($node instanceof Apishka_Templater_Node_Expression_GetAttr && (!$node->getNode('attribute') instanceof Apishka_Templater_Node_Expression_Constant || 'parent' === $node->getNode('attribute')->getAttribute('value')) && (true === $this->loops[0]->getAttribute('with_loop') || $node->getNode('node') instanceof Apishka_Templater_Node_Expression_Name && 'loop' === $node->getNode('node')->getAttribute('name'))) {
         $this->addLoopToAll();
     }
 }