/** * {@inheritdoc} */ protected function doLeaveNode(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env) { if ($node instanceof Apishka_Templater_Node_Module) { $varName = $this->getVarName(); $node->setNode('display_start', Apishka_Templater_Node::apishka(array(new Apishka_Templater_Profiler_Node_EnterProfile($this->extensionName, Apishka_Templater_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start')))); $node->setNode('display_end', Apishka_Templater_Node::apishka(array(new Apishka_Templater_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')))); } elseif ($node instanceof Apishka_Templater_Node_Block) { $varName = $this->getVarName(); $node->setNode('body', Apishka_Templater_Node_Body::apishka(array(new Apishka_Templater_Profiler_Node_EnterProfile($this->extensionName, Apishka_Templater_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), new Apishka_Templater_Profiler_Node_LeaveProfile($varName)))); } return $node; }
/** * {@inheritdoc} */ protected function doEnterNode(Apishka_Templater_NodeAbstract $node, Apishka_Templater_Environment $env) { if ($node instanceof Apishka_Templater_Node_Module) { if ($env->hasExtension('escaper') && ($defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename')))) { $this->defaultStrategy = $defaultStrategy; } $this->safeVars = array(); } elseif ($node instanceof Apishka_Templater_Node_AutoEscape) { $this->statusStack[] = $node->getAttribute('value'); } elseif ($node instanceof Apishka_Templater_Node_Block) { $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); } return $node; }
/** * Compiles a node. * * @param Apishka_Templater_Node $node The node to compile * @param int $indentation The current indentation * * @return Apishka_Templater_Compiler The current compiler instance */ public function compile(Apishka_Templater_NodeAbstract $node, $indentation = 0) { $this->_last_line = null; $this->_source = ''; $this->_debug_info = array(); $this->_source_offset = 0; // source code starts at 1 (as we then increment it when we encounter new lines) $this->_source_line = 1; $this->_indentation = $indentation; if ($node instanceof Apishka_Templater_Node_Module) { $this->_filename = $node->getAttribute('filename'); } $node->compile($this); $this->_source = str_replace('&space;', ' ', $this->_source); return $this; }
private function filterBodyNodes(Apishka_Templater_NodeAbstract $node) { // check that the body does not contain non-empty output nodes if ($node instanceof Apishka_Templater_Node_Text && !ctype_space($node->getAttribute('data')) || !$node instanceof Apishka_Templater_Node_Text && !$node instanceof Apishka_Templater_Node_BlockReference && $node instanceof Apishka_Templater_NodeOutputInterface) { if (false !== strpos((string) $node, chr(0xef) . chr(0xbb) . chr(0xbf))) { throw new Apishka_Templater_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node->getLine(), $this->getFilename()); } throw new Apishka_Templater_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename()); } // bypass "set" nodes as they "capture" the output if ($node instanceof Apishka_Templater_Node_Set) { return $node; } if ($node instanceof Apishka_Templater_NodeOutputInterface) { return; } foreach ($node as $k => $n) { if (null !== $n && null === $this->filterBodyNodes($n)) { $node->removeNode($k); } } return $node; }