Ejemplo n.º 1
0
 /**
  * Processes the loop separator. The programmer must provide the
  * variable name that will be used to check if we need to apply
  * the separator, and the optional value of "separator" attribute
  * in the node attributes. The separator is added to the specified
  * XML node.
  *
  * If the node contains too many opt:separator tags, an exception
  * is thrown.
  *
  * @param string $varname The internal variable name
  * @param string $arg The value of "separator" attribute
  * @param Opt_Xml_Scannable $node The node the separator will be added to.
  * @throws Opt_InstructionTooManyItems_Exception
  */
 public function processSeparator($varname, $arg, Opt_Xml_Scannable $node)
 {
     $items = $node->getElementsByTagNameNS('opt', 'separator', false);
     switch (sizeof($items)) {
         case 1:
             // Move this node to the beginning
             $node->removeChild($items[0]);
             $node->insertBefore($items[0], 0);
             $this->_process($items[0]);
             $items[0]->set('hidden', false);
             // Add PHP code
             $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' ' . $varname . ' = 0;');
             $items[0]->addBefore(Opt_Xml_Buffer::TAG_BEFORE, 'if(' . $varname . ' == 1){');
             $items[0]->addAfter(Opt_Xml_Buffer::TAG_AFTER, '}else{ ' . $varname . ' = 1; }');
             break;
         case 0:
             if (!is_null($arg)) {
                 $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, $varname . ' = 0;');
                 $node->addBefore(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if(' . $varname . ' == 1){ echo ' . $arg . '; }else{ ' . $varname . ' = 1; }');
             }
             break;
         default:
             throw new Opt_InstructionTooManyItems_Exception('opt:separator', $node->getXmlName(), 'Zero or one');
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructs a new object of Opt_Xml_Text. The first argument may be
  * used to initialize the first Opt_Xml_Cdata node.
  *
  * @param String $cdata The optional text to initialize the Opt_Xml_Cdata.
  */
 public function __construct($cdata = null)
 {
     parent::__construct();
     if (!is_null($cdata)) {
         $this->appendData($cdata);
     }
 }
Ejemplo n.º 3
0
 /**
  * Skip this test due to a bug in PHPUnit.
  *
  * @skip
  * @covers Opt_Xml_Scannable::insertBefore
  */
 public function testInsertBefore()
 {
     $mock = array(0 => $this->getMock('Opt_Xml_Node'));
     $mock[0]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $mock[1] = $this->getMock('Opt_Xml_Node');
     $mock[1]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $mock[2] = $this->getMock('Opt_Xml_Node');
     $mock[2]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $this->_obj->appendChild($mock[0]);
     $this->_obj->appendChild($mock[1]);
     $this->_obj->insertBefore($mock[2], 1);
     $suggestedOutput = array(0 => $mock[0], $mock[2], $mock[1]);
     $i = 0;
     foreach ($this->_obj as $obj) {
         $this->assertSame($suggestedOutput[$i], $obj);
         $i++;
     }
 }
Ejemplo n.º 4
0
 /**
  * Sets the new node children queue used in stages 2 and 3 of the compilation.
  *
  * @param SplQueue|Opt_Xml_Scannable $children The children list.
  */
 public function setChildren($children)
 {
     if ($children instanceof SplQueue) {
         if ($children->count() > 0) {
             $this->_newQueue = $children;
         }
     } else {
         if ($children instanceof Opt_Xml_Scannable) {
             if ($children->hasChildren() > 0) {
                 $this->_newQueue = new SplQueue();
                 foreach ($children as $child) {
                     $this->_newQueue->enqueue($child);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Creates a new XML tag with the specified name. The accepted
  * name format is 'name' or 'namespace:name'.
  *
  * @param String $name The tag name.
  */
 public function __construct($name)
 {
     parent::__construct();
     $this->setName($name);
 }
Ejemplo n.º 6
0
 /**
  * Constructs the root node.
  */
 public function __construct()
 {
     parent::__construct();
 }