예제 #1
0
 /**
  * Processes the opt:root node.
  * @internal
  * @param Opt_Xml_Node $node The recognized node.
  */
 public function processNode(Opt_Xml_Node $node)
 {
     if ($node->getParent()->getType() != 'Opt_Xml_Root') {
         throw new Opt_InstructionInvalidParent_Exception($node->getXmlName(), 'ROOT');
     }
     $params = array('escaping' => array(0 => self::OPTIONAL, self::BOOL, NULL), 'include' => array(0 => self::OPTIONAL, self::STRING, NULL), 'dynamic' => array(0 => self::OPTIONAL, self::BOOL, false));
     $this->_extractAttributes($node, $params);
     // Compile-time inclusion support
     if (!is_null($params['include'])) {
         $file = $params['include'];
         if ($params['dynamic']) {
             if (is_null($file = $this->_compiler->inherits($this->_compiler->get('currentTemplate')))) {
                 $file = $params['include'];
             }
         }
         $this->_compiler->addDependantTemplate($file);
         $compiler = new Opt_Compiler_Class($this->_compiler);
         $compiler->compile($this->_tpl->_getSource($file), $file, NULL, $this->_compiler->get('mode'));
         $this->_compiler->importDependencies($compiler);
     }
     // Escaping control support
     if (!is_null($params['escaping'])) {
         $this->_compiler->set('escaping', $params['escaping']);
     }
     $this->_process($node);
 }
예제 #2
0
 /**
  * Processes the opt:extend node.
  * @internal
  * @param Opt_Xml_Node $node The recognized node.
  */
 public function processNode(Opt_Xml_Node $node)
 {
     if ($node->getParent()->getType() != 'Opt_Xml_Root') {
         throw new Opt_InstructionInvalidParent_Exception($node->getXmlName(), 'ROOT');
     }
     $params = array('file' => array(0 => self::REQUIRED, self::STRING), 'escaping' => array(0 => self::OPTIONAL, self::BOOL, NULL), 'dynamic' => array(0 => self::OPTIONAL, self::BOOL, false), '__UNKNOWN__' => array(0 => self::OPTIONAL, self::STRING, null));
     $branches = $this->_extractAttributes($node, $params);
     if (!is_null($params['escaping'])) {
         $this->_compiler->set('escaping', $params['escaping']);
     }
     if ($params['dynamic'] && !is_null($branch = $this->_compiler->inherits($this->_compiler->get('currentTemplate')))) {
     } elseif (isset($branches[$this->_compiler->get('branch')])) {
         $branch = $branches[$this->_compiler->get('branch')];
     } else {
         $branch = $params['file'];
     }
     $node->set('branch', $branch);
     $node->set('postprocess', true);
     $this->_process($node);
 }
예제 #3
0
 /**
  * Processes the opt:if and opt:omit-tag attributes.
  * @internal
  * @param Opt_Xml_Node $node The node with the attribute
  * @param Opt_Xml_Attribute $attr The recognized attribute.
  */
 public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
 {
     // TODO: Add opt:omit-tag implementation, changed opt:on->opt:omit-tag, it should work as before
     switch ($attr->getName()) {
         case 'omit-tag':
             if (!$this->_compiler->isNamespace($node->getNamespace())) {
                 $expr = $this->_compiler->compileExpression((string) $attr, false, Opt_Compiler_Class::ESCAPE_OFF);
                 $node->addBefore(Opt_Xml_Buffer::TAG_OPENING_BEFORE, ' $_tag_' . $this->_cnt . ' = false; if(' . $expr[0] . '){ $_tag_' . $this->_cnt . ' = true; ');
                 $node->addAfter(Opt_Xml_Buffer::TAG_OPENING_AFTER, ' } ');
                 $node->addBefore(Opt_Xml_Buffer::TAG_CLOSING_BEFORE, ' if($_tag_' . $this->_cnt . ' === true){ ');
                 $node->addAfter(Opt_Xml_Buffer::TAG_CLOSING_AFTER, ' } ');
                 $this->_cnt++;
                 break;
             }
         case 'if':
             // opt:if added to an section must be handled differently.
             // Wait for the section processor and add the condition in the postprocessing.
             if ($this->_compiler->isInstruction($node->getXmlName()) instanceof Opt_Instruction_BaseSection) {
                 $attr->set('postprocess', true);
                 return;
             }
             $expr = $this->_compiler->compileExpression((string) $attr, false, Opt_Compiler_Class::ESCAPE_OFF);
             $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' if(' . $expr[0] . '){ ');
             $node->addAfter(Opt_Xml_Buffer::TAG_AFTER, ' } ');
     }
 }
예제 #4
0
 /**
  * Processes the opt:single instruction attribute.
  *
  * @internal
  * @param Opt_Xml_Node $node XML node.
  * @param Opt_Xml_Attribute $attr XML attribute.
  * @throws Opt_AttributeInvalidNamespace_Exception
  */
 public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
 {
     if ($this->_compiler->isNamespace($node->getNamespace())) {
         throw new Opt_AttributeInvalidNamespace_Exception($node->getXmlName());
     }
     if ($attr->getValue() == 'yes') {
         $attr->set('postprocess', true);
     }
 }