示例#1
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, ' } ');
     }
 }
示例#2
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);
     }
 }