本文整理汇总了PHP中Node::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::setAttribute方法的具体用法?PHP Node::setAttribute怎么用?PHP Node::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::setAttribute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attributeAccessors
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: applyArgs
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: parseTag
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: getNode
/**
* 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;
}
示例5: addFormValue
/**
* 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: parseSharp
function parseSharp(&$token, Node &$data){
return $data->setAttribute('id', $token);
}
示例7: testRunFinished
/**
* 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());
}