Example #1
0
 /**
  * Processes the opt:parent element.
  * @internal
  * @param Opt_Xml_Element $node The found element.
  */
 public function _processParent(Opt_Xml_Element $node)
 {
     $n = $node->get('snippetName');
     $i = $node->get('snippetId');
     // If there is a parent, append it here and execute.
     if (isset($this->_snippets[$n][$i])) {
         $node->set('escaping', $this->_compiler->get('escaping'));
         $node->set('single', false);
         $this->_compiler->set('escaping', $this->_snippets[$n][$i]->get('escaping'));
         foreach ($this->_snippets[$n][$i] as $subnode) {
             $node->appendChild(clone $subnode);
         }
         $node->set('postprocess', true);
         $this->_process($node);
     }
 }
Example #2
0
 /**
  * The internal magic shared by the selector elements. Locates the node elements
  * and constructs the switch() statement for them.
  * @internal
  * @param Opt_Xml_Element $node The found element
  * @param array $section The reference to the section data.
  * @param string $type The name of the selection item.
  * @throws Opt_InstructionTooManyItems_Exception
  */
 private function _internalMagic($node, &$section, $type)
 {
     $section['format']->assign('item', !$type ? $section['test'] : 'item');
     // Check, if there are no instruction tags in the children list.
     $instructions = array();
     $cases = array();
     $alternative = null;
     foreach ($node as $subnode) {
         if ($subnode instanceof Opt_Xml_Element && $this->_compiler->isNamespace($subnode->getNamespace())) {
             if ($this->_compiler->isInstruction($subnode->getXmlName()) || $subnode->getXmlName() == 'opt:separator') {
                 if ($subnode != 'opt:selectorelse') {
                     $instructions[] = $subnode;
                 } else {
                     if (!is_null($alternative)) {
                         throw new Opt_InstructionTooManyItems_Exception('opt:selectorelse', $node->getXmlName(), 'Zero or one');
                     }
                     $alternative = $subnode;
                 }
             } else {
                 $cases[] = $subnode;
             }
         } else {
             $node->removeChild($subnode);
         }
     }
     if (sizeof($instructions) > 0) {
         // There are instructions in opt:selector. We have to move the
         // cases to a fake node in order to sanitize them.
         $node->removeChildren();
         foreach ($instructions as $instruction) {
             $node->appendChild($instruction);
         }
         $fake = new Opt_Xml_Element('opt:_');
         foreach ($cases as $case) {
             $fake->appendChild($case);
         }
         $fake->set('processAll', true);
         $fake->set('hidden', false);
         $node->appendChild($fake);
         if (!is_null($alternative)) {
             $node->appendChild($alternative);
         }
     } else {
         $fake = $node;
     }
     $fake->addAfter(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'switch(' . $section['format']->get('section:variable') . '){');
     // If opt:selectorelse is used, the ending curly bracket is created by
     // _processSelectorelse().
     if (is_null($alternative)) {
         $fake->addBefore(Opt_Xml_Buffer::TAG_CONTENT_AFTER, ' } ');
     }
     foreach ($cases as $case) {
         if ($case->getXmlName() == 'opt:separator') {
             Opl_Debug::write('Print shit');
         }
         if ($case->getName() == 'default') {
             $case->addAfter(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, ' default: ');
         } else {
             $case->addAfter(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, ' case \'' . $case->getName() . '\': ');
         }
         $case->addBefore(Opt_Xml_Buffer::TAG_CONTENT_AFTER, ' break; ');
         $case->set('processAll', true);
         $case->set('hidden', false);
     }
 }
Example #3
0
 public function testScannableInsertBefore2()
 {
     $topNode = new Opt_Xml_Element('foo');
     $subnodes = array(0 => new Opt_Xml_Element('bar'), new Opt_Xml_Element('joe'), new Opt_Xml_Element('goo'));
     $topNode->appendChild($subnodes[0]);
     $topNode->appendChild($subnodes[1]);
     $topNode->insertBefore($subnodes[2]);
     $ok = true;
     $i = 0;
     foreach ($topNode as $n) {
         if ($n !== $subnodes[$i]) {
             $ok = false;
         }
         $i++;
     }
     $this->assertTrue($ok);
 }