Пример #1
0
 public function attributeAccessors()
 {
     $n = new Node('node');
     $n->setAttribute('id', 1);
     $this->assertTrue($n->hasAttribute('id'));
     $this->assertFalse($n->hasAttribute('href'));
     $this->assertEquals(1, $n->getAttribute('id'));
 }
Пример #2
0
 protected function applyArgs(Node $node)
 {
     if ($node instanceof TextNode) {
         $node->setContent($this->interpolate($node->getContent()));
     } else {
         if ($node instanceof Element) {
             foreach ($node->getAttributes() as $attr => $value) {
                 $node->setAttribute($attr, $this->interpolate($value));
             }
         }
     }
     foreach ($node->getChildren() as $child) {
         $this->applyArgs($child);
     }
 }
Пример #3
0
 protected function parseTag()
 {
     $name = $this->lexer->getAdvancedToken()->value;
     $node = new Node('tag', $name);
     // Parse id, class, attributes token
     while (true) {
         switch ($this->lexer->predictToken()->type) {
             case 'id':
             case 'class':
                 $token = $this->lexer->getAdvancedToken();
                 $node->setAttribute($token->type, $token->value);
                 continue;
             case 'attributes':
                 foreach ($this->lexer->getAdvancedToken()->attributes as $name => $value) {
                     $node->setAttribute($name, $value);
                 }
                 continue;
             default:
                 break 2;
         }
     }
     // Parse text/code token
     switch ($this->lexer->predictToken()->type) {
         case 'text':
             $node->text = $this->parseText(true);
             break;
         case 'code':
             $node->code = $this->parseCode();
             break;
     }
     // Skip newlines
     while ($this->lexer->predictToken()->type === 'newline') {
         $this->lexer->getAdvancedToken();
     }
     // Tag text on newline
     if ($this->lexer->predictToken()->type === 'text') {
         if ($text = $node->text) {
             $text->addLine('');
         } else {
             $node->text = new Node('text', '');
         }
     }
     // Parse block indentation
     if ($this->lexer->predictToken()->type === 'indent') {
         $node->addChild($this->parseBlock());
     }
     return $node;
 }
Пример #4
0
 /**
  * Return the XML representation of this node
  *
  * @return  &xml.Node
  */
 public function getNode()
 {
     $Node = new Node($this->node_name);
     $Node->setAttribute('parent', $this->parent);
     return $Node;
 }
 /**
  * Add a child to the formvalues node. The XML representation
  * is probably best shown with a couple of examples:
  *
  * Example: a string
  * <xmp>
  *   <param name="__form" xsi:type="xsd:string">new</param>
  * </xmp>
  *
  * Example: an associative array
  * <xmp>
  *   <param name="data[domain]" xsi:type="xsd:string">thekidabc</param>
  *   <param name="data[tld]" xsi:type="xsd:string">de</param>
  * </xmp>
  *
  * Example: an object
  * <xmp>
  *   <param name="faxnumber" xsi:type="xsd:object">
  *     <pre>721</pre>
  *     <number>1234567</number>
  *     <lcode>+49</lcode>
  *   </param>
  * </xmp>     
  *
  * @param   string name name
  * @param   var val
  */
 public function addFormValue($name, $values)
 {
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($values as $k => $val) {
         try {
             if (is_array($val)) {
                 $c = Node::fromArray($val, 'param');
             } else {
                 if (is_object($val)) {
                     $c = Node::fromObject($val, 'param');
                 } else {
                     $c = new Node('param', $val);
                 }
             }
             $c->setAttribute('name', $name . (is_int($k) ? '' : '[' . $k . ']'));
             $c->setAttribute('xsi:type', 'xsd:' . gettype($val));
         } catch (XMLFormatException $e) {
             // An XMLFormatException indicates data we have received on-wire
             // does not conform to XML rules - eg. contains characters that are
             // not allowed within XML documents. As on-wire data is beyond the
             // classes control, this must be handled to prevent application
             // breakage.
             // Passing special XML characters such as < or & will not fall into this
             // block - they'll just be converted to their counterpart XML entities.
             $c = new Node('param', NULL, array('name' => $name, 'xsi:type' => 'xsd:null', 'error' => 'formaterror'));
         }
         $this->document->formvalues->addChild($c);
     }
 }
Пример #6
0
	function parseSharp(&$token, Node &$data){
		return $data->setAttribute('id', $token);
	}
 /**
  * Called when a test run finishes.
  *
  * @param   unittest.TestSuite suite
  * @param   unittest.TestResult result
  */
 public function testRunFinished(TestSuite $suite, TestResult $result)
 {
     $coverage = xdebug_get_code_coverage();
     xdebug_stop_code_coverage();
     $results = array();
     foreach ($coverage as $fileName => $data) {
         foreach ($this->paths as $path) {
             if (substr($fileName, 0, strlen($path)) !== $path) {
                 continue;
             }
             $results[dirname($fileName)][basename($fileName)] = $data;
             break;
         }
     }
     $pathsNode = new Node('paths');
     foreach ($results as $pathName => $files) {
         $pathNode = new Node('path');
         $pathNode->setAttribute('name', $pathName);
         foreach ($files as $fileName => $data) {
             $fileNode = new Node('file');
             $fileNode->setAttribute('name', $fileName);
             $num = 1;
             $handle = fopen($pathName . '/' . $fileName, 'r');
             while (!feof($handle)) {
                 $line = stream_get_line($handle, 1000, "\n");
                 $lineNode = new Node('line', new CData($line));
                 if (isset($data[$num])) {
                     if ($data[$num] > 0 || $data[$num] < -1) {
                         $lineNode->setAttribute('checked', 'checked');
                     } elseif ($data[$num] > -2) {
                         $lineNode->setAttribute('unchecked', 'unchecked');
                     }
                 }
                 $fileNode->addChild($lineNode);
                 ++$num;
             }
             $pathNode->addChild($fileNode);
         }
         $pathsNode->addChild($pathNode);
     }
     $now = time();
     $pathsNode->setAttribute('time', date('Y-m-d H:i:s'));
     $this->processor->setXMLBuf($pathsNode->getSource());
     $this->processor->run();
     $reportfile = 'coverage-' . date('Y-m-d-H-i-s') . '.html';
     $reportfile = 'coverage.html';
     file_put_contents($reportfile, $this->processor->output());
 }