本文整理汇总了PHP中Node::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::setAttributes方法的具体用法?PHP Node::setAttributes怎么用?PHP Node::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::setAttributes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmlToObject
/**
* Converts an XML string into an object struct.
*
* @param string $data The XML string
*
* @return esXml The parsed XML
*/
private function xmlToObject($data)
{
$root = new Node();
$root->setName('root');
$actualLevel = 1;
$actualNode = $root;
$stack = array();
$stack[1] = $root;
foreach ($this->parseIntoStruct($data) as $element) {
if ($element['type'] === 'close') {
continue;
}
$node = new Node();
$node->setName($element['tag']);
if (isset($element['attributes'])) {
$node->setAttributes($element['attributes']);
}
if (isset($element['value'])) {
$node->setValue($element['value']);
}
$level = $element['level'];
if ($level > $actualLevel) {
$stack[$level] = $actualNode;
}
$stack[$level]->addChild($node);
$actualNode = $node;
$actualLevel = $element['level'];
}
$children = $root->getChildren();
unset($root);
return $children[0]->setParent(null);
}
示例2: createNodeFromElement
private function createNodeFromElement($elem, $parent)
{
$node = new Node();
$node->setParent($parent);
$node->setType($elem->nodeName);
$node->setText($elem->nodeValue);
$node->setDepth($parent->getDepth() + 1);
$node->setAttributes($this->getElementAttributes($elem));
return $node;
}
示例3: addFormError
/**
* Adds an error. The XML representation will look like this:
* <xmp>
* <error
* checker="foo.bar.wrapper.MyLoginDataChecker"
* type="user_nonexistant"
* field="username"
* />
* </xmp>
*
* @param string checker The class checking the input
* @param string type The error type
* @param string field default '*' The form field corresponding
* @param var info default NULL
* @return bool FALSE
*/
public function addFormError($checker, $type, $field = '*', $info = NULL)
{
if (is_array($info)) {
$c = Node::fromArray($info, 'error');
} else {
if (is_object($info)) {
$c = Node::fromObject($info, 'error');
} else {
$c = new Node('error', $info);
}
}
$c->setAttributes(array('type' => $type, 'field' => $field, 'checker' => $checker));
$this->document->formerrors->addChild($c);
return FALSE;
}
示例4: insertDefaultNodes
public function insertDefaultNodes($mindmapId)
{
$parent = false;
foreach ($this->_defaultNodes as $dnode) {
$node = new Node();
$node->setAttributes($dnode);
$node->mindmap_id = $mindmapId;
if ($parent) {
$node->parent_id = $parent;
}
if (!$node->save()) {
return false;
}
if ($dnode['type'] == 1) {
$parent = $node->id;
}
}
return true;
}