/**
  * @covers Opt_Xml_Buffer::copyBuffer
  */
 public function testCopyBufferExisting()
 {
     $this->_obj->addAfter(Opt_Xml_Buffer::TAG_BEFORE, 'foo');
     $obj2 = new Opt_Xml_Element('opt:foo');
     $obj2->addAfter(Opt_Xml_Buffer::TAG_AFTER, 'bar');
     $obj2->copyBuffer($this->_obj, Opt_Xml_Buffer::TAG_BEFORE, Opt_Xml_Buffer::TAG_AFTER);
     $buf1 = $obj2->getBuffer(Opt_Xml_Buffer::TAG_AFTER);
     $this->assertEquals(array('foo', 'bar'), $buf1);
 }
 /**
  * Adds the show condition PHP code to the specified node, using the
  * information from the section record.
  *
  * @internal
  * @param Opt_Xml_Element $node The node, where to add the show condition.
  * @param Array &$section The section info record
  */
 private function _createShowCondition(Opt_Xml_Element $node, &$section)
 {
     // First, try to check for the call:use tag variable.
     if ($node->get('call:use') !== NULL) {
         $section['node']->set('call:use', $node->get('call:use'));
     }
     // Deal with the data formats
     $format = $section['format'];
     $format->assign('section', $section);
     $request = $format->property('section:anyRequests');
     if (!is_null($request)) {
         // Send the requested data, if the data format needs any.
         switch ($request) {
             case 'ancestorNames':
                 self::$_stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
                 $list = array();
                 $parent = $section['parent'];
                 foreach (self::$_stack as $up) {
                     if ($up == $parent) {
                         $parent = self::$_sections[$up]['parent'];
                         $list[] = self::$_sections[$up]['name'];
                     }
                 }
                 $format->assign('requestedData', array_reverse($list));
                 break;
             case 'ancestorNumbers':
                 self::$_stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
                 $list = array();
                 $parent = $section['parent'];
                 $iteration = self::$_stack->count();
                 foreach (self::$_stack as $up) {
                     if ($up == $parent) {
                         $parent = self::$_sections[$up]['parent'];
                         $list[] = $iteration;
                     }
                     $iteration--;
                 }
                 $format->assign('requestedData', array_reverse($list));
                 break;
         }
     }
     $code = $format->get('section:init');
     if (is_null($section['display'])) {
         $code .= ' if(' . $format->get('section:isNotEmpty') . '){ ';
     } else {
         $code .= ' if(' . $format->get('section:isNotEmpty') . ' && ' . $section['display'] . '){ ';
     }
     $code .= $format->get('section:started');
     $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, $code);
     $code = $format->get('section:finished') . ' } ' . $format->get('section:done');
     $node->addAfter(Opt_Xml_Buffer::TAG_AFTER, $code);
     $node->set('priv:initialized', true);
 }
Exemple #3
0
 /**
  * The common processing part of the dynamically and statically
  * deployed components. Returns the compiled PHP code ready to
  * be appended to the XML tag. The caller must generate a component
  * variable name that will be used in the generated code to refer
  * to the component object. Furthermore, he must pass the returned results
  * of _extractAttributes() method.
  *
  * @internal
  * @param Opt_Xml_Element $node The node with the component data.
  * @param string $blockVariable The PHP block variable name.
  * @param array $args The array of custom block attributes.
  * @return string
  */
 private function _commonProcessing(Opt_Xml_Element $node, $blockVariable, array $args)
 {
     // Common part of the component processing
     $argList = 'array( ';
     foreach ($args as $name => $value) {
         $argList .= '\'' . $name . '\' => ' . $value . ', ';
     }
     $argList .= ')';
     if ($node->get('single')) {
         $node->addAfter(Opt_Xml_Buffer::TAG_SINGLE_BEFORE, $blockVariable . '->onSingle(' . $argList . '); ');
     } else {
         $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, ' if(' . $blockVariable . '->onOpen(' . $argList . ')){ ');
         $node->addBefore(Opt_Xml_Buffer::TAG_AFTER, ' } ' . $blockVariable . '->onClose(); ');
     }
     $this->_process($node);
 }