本文整理汇总了PHP中Node::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::addChild方法的具体用法?PHP Node::addChild怎么用?PHP Node::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addWebdavVersionContainer
/**
* Apply an WebdavObject
*
* @param org.webdav.version.WebdavVersionContainer container
*/
public function addWebdavVersionContainer($container)
{
foreach ($container->getVersions() as $version) {
$res = new Node('D:response');
$res->addChild(new Node('D:href', $version->getHref()));
$propstat = $res->addChild(new Node('D:propstat'));
with($props = $propstat->addChild(new Node('D:prop')));
$props->addChild(new Node('D:version-name', $version->getVersionNumber()));
$props->addChild(new Node('D:creator-displayname', $version->getCreatorName()));
$props->addChild(new Node('D:getcontentlength', $version->getContentLength()));
$props->addChild(new Node('D:getlastmodified', $version->lastmodified->toString()));
$propstat->addChild(new Node('D:status', 'HTTP/1.1 200 OK'));
$this->addChild($res);
}
}
示例2: set
/**
* sets a specific parameter
*
* @param $key
* @param $val
*
* @return mixed
*/
public function set($key, $val)
{
// set the variable
if (empty($key)) {
return $this;
}
$node = new Node($this->mainNode, $key, $val);
$this->mainNode->addChild($node);
return $this;
}
示例3: expandBranch
private function expandBranch($name, Node $parent)
{
$list = explode('\\', $name);
foreach ($list as $item) {
$node = new Node();
$parent->addChild(strtolower($item), $node);
$parent = $node;
}
return $node;
}
示例4: setUp
function setUp()
{
$this->parent = new Person('John', 'Doe', 1);
$this->child = new Person('John', 'Doe, Jr.', 2);
// set up complex tree
/**
* Grandaddy 85
* Daddy 50
* Grandkid1 22
* Grandkid2 25
* Aunt 48
* Grandkid3 18
*/
$granddaddy = new Node();
$granddaddy->name = 'Granddaddy';
$granddaddy->value = 85;
$bro1 = new Node();
$bro1->name = 'Daddy';
$bro1->value = 50;
$granddaddy->addChild($bro1);
$sis1 = new Node();
$sis1->name = 'Aunt';
$sis1->value = 48;
$granddaddy->addChild($sis1);
$grandkid1 = new Node();
$grandkid1->name = 'Grandkid1';
$grandkid1->value = 22;
$bro1->addChild($grandkid1);
$grandkid2 = new Node();
$grandkid2->name = 'Grandkid2';
$grandkid2->value = 25;
$bro1->addChild($grandkid2);
$grandkid3 = new Node();
$grandkid3->name = 'Grandkid3';
$grandkid3->value = 18;
$sis1->addChild($grandkid3);
$this->nodeTree = $granddaddy;
$objectHolder = new ObjectHolder();
$objectHolder->myObject = $granddaddy;
$this->objectHolder = $objectHolder;
}
示例5: addProperty
/**
* Adds a new property to this template.
*
* @param $node The property node
*/
public function addProperty(PropertyNode $node)
{
if ($node->getKey() == null) {
$this->propertyMap[$this->curIndex] = $node;
$node->setKey($this->curIndex);
$this->curIndex++;
} else {
//If there is already a property with the same key, remove it from the children list
if (isset($this->propertyMap[$node->getKey()])) {
$this->removeChild($this->propertyMap[$node->getKey()]);
}
$this->propertyMap[$node->getKey()] = $node;
}
parent::addChild($node);
}
示例6: createFromPath
/**
* @param string $path
*
* @return Node
*/
public function createFromPath($path)
{
$file = new \SplFileInfo($path);
$node = new Node($file);
if (!$file->isDir()) {
return $node;
}
$iterator = new \DirectoryIterator($path);
foreach ($iterator as $childFile) {
if ($childFile->isDot()) {
continue;
}
$node->addChild($this->createFromPath($childFile->getRealPath()));
}
return $node;
}
示例7: setParent
/**
* Sets the parent node.
*
* @param AbstractNode $parent
* @chainable
* @throws CircularException
*/
public function setParent(AbstractNode $parent)
{
// check integrity
if ($this->isDescendant($parent->id())) {
throw new CircularException('Can not add descendant "' . $parent->id() . '" as my parent.');
}
// remove from old parent
if (!is_null($this->parent)) {
if ($this->parent->id() == $parent->id()) {
// already the parent
return $this;
}
$this->parent->removeChild($this->id);
}
$this->parent = $parent;
// assign child to parent
$this->parent->addChild($this);
//clear any cache
$this->clear();
return $this;
}
示例8: explode
$tokens = explode(" ", $parsed);
// var_dump($tokens);
foreach ($tokens as $token) {
if (strcmp(substr($token, 0, 1), "(") == 0) {
//nāk jauna frāze, jātaisa jauna lapa
$tokenCategory = trim(substr($token, 1));
if (!isset($rootNode)) {
$rootNode = new Node($tokenCategory);
$currentNode = $rootNode;
$currentNode->level = 0;
} else {
$newNode = new Node($tokenCategory);
$newNode->setParent($currentNode);
$newNode->level = $currentNode->level + 1;
if (!$rootNode->hasChildren()) {
$rootNode->addChild($newNode);
} else {
$currentNode->addChild($newNode);
}
$currentNode = $newNode;
}
} elseif (strcmp(substr($token, -1, 1), ")") == 0) {
//frāze beidzas
//ja bija vārds, jāpievieno pie aktuālās lapas, ja nē, jāiet pie vecāka
$tokenWord = substr($token, 0, -1);
if (strlen($tokenWord) > 0) {
$currentNode->setWord($tokenWord);
}
if ($currentNode->getParent() != null) {
$currentNode = $currentNode->getParent();
}
示例9: groupNode
/**
* Recursively groups tree nodes given a separator
*
* @param Node $node The node to group
*
* @return void
*/
public function groupNode($node)
{
if ($node->type != Node::CONTAINER || !$GLOBALS['cfg']['NavigationTreeEnableExpansion']) {
return;
}
$separators = array();
if (is_array($node->separator)) {
$separators = $node->separator;
} else {
if (strlen($node->separator)) {
$separators[] = $node->separator;
}
}
$prefixes = array();
if ($node->separator_depth > 0) {
foreach ($node->children as $child) {
$prefix_pos = false;
foreach ($separators as $separator) {
$sep_pos = mb_strpos($child->name, $separator);
if ($sep_pos != false && $sep_pos != mb_strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) {
$prefix_pos = $sep_pos;
}
}
if ($prefix_pos !== false) {
$prefix = mb_substr($child->name, 0, $prefix_pos);
if (!isset($prefixes[$prefix])) {
$prefixes[$prefix] = 1;
} else {
$prefixes[$prefix]++;
}
}
//Bug #4375: Check if prefix is the name of a DB, to create a group.
foreach ($node->children as $child) {
if (array_key_exists($child->name, $prefixes)) {
$prefixes[$child->name]++;
}
}
}
//Check if prefix is the name of a DB, to create a group.
foreach ($node->children as $child) {
if (array_key_exists($child->name, $prefixes)) {
$prefixes[$child->name]++;
}
}
}
foreach ($prefixes as $key => $value) {
if ($value == 1) {
unset($prefixes[$key]);
} else {
if ($value > 500 && !$this->_largeGroupWarning) {
trigger_error(__('There are large item groups in navigation panel which ' . 'may affect the performance. Consider disabling item ' . 'grouping in the navigation panel.'), E_USER_WARNING);
$this->_largeGroupWarning = true;
}
}
}
if (count($prefixes)) {
$groups = array();
foreach ($prefixes as $key => $value) {
$groups[$key] = new Node($key, Node::CONTAINER, true);
$groups[$key]->separator = $node->separator;
$groups[$key]->separator_depth = $node->separator_depth - 1;
$groups[$key]->icon = PMA_Util::getImage('b_group.png');
$groups[$key]->pos2 = $node->pos2;
$groups[$key]->pos3 = $node->pos3;
if ($node instanceof Node_Table_Container || $node instanceof Node_View_Container) {
$tblGroup = '&tbl_group=' . urlencode($key);
$groups[$key]->links = array('text' => $node->links['text'] . $tblGroup, 'icon' => $node->links['icon'] . $tblGroup);
}
$node->addChild($groups[$key]);
foreach ($separators as $separator) {
$separatorLength = strlen($separator);
// FIXME: this could be more efficient
foreach ($node->children as $child) {
$keySeparatorLength = mb_strlen($key) + $separatorLength;
$name_substring = mb_substr($child->name, 0, $keySeparatorLength);
if ($name_substring != $key . $separator && $child->name != $key || $child->type != Node::OBJECT) {
continue;
}
$class = get_class($child);
$new_child = PMA_NodeFactory::getInstance($class, mb_substr($child->name, $keySeparatorLength));
if ($new_child instanceof Node_Database && $child->getHiddenCount() > 0) {
$new_child->setHiddenCount($child->getHiddenCount());
}
$new_child->real_name = $child->real_name;
$new_child->icon = $child->icon;
$new_child->links = $child->links;
$new_child->pos2 = $child->pos2;
$new_child->pos3 = $child->pos3;
$groups[$key]->addChild($new_child);
foreach ($child->children as $elm) {
$new_child->addChild($elm);
}
$node->removeChild($child->name);
//.........这里部分代码省略.........
示例10: 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;
}
示例11: groupNode
/**
* Recursively groups tree nodes given a sperarator
*
* @param Node $node The node to group
*
* @return void
*/
public function groupNode($node)
{
if ($node->type == Node::CONTAINER) {
$separators = array();
if (is_array($node->separator)) {
$separators = $node->separator;
} else {
if (strlen($node->separator)) {
$separators[] = $node->separator;
}
}
$prefixes = array();
if ($node->separator_depth > 0) {
foreach ($node->children as $child) {
$prefix_pos = false;
foreach ($separators as $separator) {
$sep_pos = strpos($child->name, $separator);
if ($sep_pos != false && $sep_pos != strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) {
$prefix_pos = $sep_pos;
}
}
if ($prefix_pos !== false) {
$prefix = substr($child->name, 0, $prefix_pos);
if (!isset($prefixes[$prefix])) {
$prefixes[$prefix] = 1;
} else {
$prefixes[$prefix]++;
}
}
}
}
foreach ($prefixes as $key => $value) {
if ($value == 1) {
unset($prefixes[$key]);
}
}
if (count($prefixes)) {
$groups = array();
foreach ($prefixes as $key => $value) {
$groups[$key] = new Node($key, Node::CONTAINER, true);
$groups[$key]->separator = $node->separator;
$groups[$key]->separator_depth = $node->separator_depth - 1;
$groups[$key]->icon = '';
if (in_array($GLOBALS['cfg']['TableNavigationLinksMode'], array('icons', 'both'))) {
$groups[$key]->icon = PMA_Util::getImage('b_group.png');
}
$groups[$key]->pos2 = $node->pos2;
$groups[$key]->pos3 = $node->pos3;
$node->addChild($groups[$key]);
foreach ($separators as $separator) {
// FIXME: this could be more efficient
foreach ($node->children as $child) {
$name_substring = substr($child->name, 0, strlen($key) + strlen($separator));
if ($name_substring == $key . $separator && $child->type == Node::OBJECT) {
$class = get_class($child);
$new_child = PMA_NodeFactory::getInstance($class, substr($child->name, strlen($key) + strlen($separator)));
$new_child->real_name = $child->real_name;
$new_child->icon = $child->icon;
$new_child->links = $child->links;
$new_child->pos2 = $child->pos2;
$new_child->pos3 = $child->pos3;
$groups[$key]->addChild($new_child);
foreach ($child->children as $elm) {
$new_child->addChild($elm);
}
$node->removeChild($child->name);
}
}
}
}
foreach ($prefixes as $key => $value) {
$this->groupNode($groups[$key]);
$groups[$key]->classes = "navGroup";
}
}
}
}
示例12: _marshall
/**
* Recursivly serialize data to the given node.
*
* Scalar values are natively supported by the protocol, so we just encode
* them as the spec tells us. As arrays and structs / hashes are the same
* in PHP, and structs are the more powerful construct, we're always encoding
* arrays as structs.
*
* XP objects are encoded as structs, having their FQDN stored in the member
* __xp_class.
*
* @param xml.Node node
* @param var data
* @throws lang.IllegalArgumentException in case the data could not be serialized.
*/
protected function _marshall($data)
{
$value = new Node('value');
// Handle objects:
// - util.Date objects are serialized as dateTime.iso8601
// - lang.types.Bytes object are serialized as base64
// - Provide a standard-way to serialize Object-derived classes
if ($data instanceof Date) {
$value->addChild(new Node('dateTime.iso8601', $data->toString('Ymd\\TH:i:s')));
return $value;
} else {
if ($data instanceof Bytes) {
$value->addChild(new Node('base64', base64_encode($data)));
return $value;
} else {
if ($data instanceof Generic) {
$n = $value->addChild(new Node('struct'));
$n->addChild(Node::fromArray(array('name' => '__xp_class', 'value' => array('string' => $data->getClassName())), 'member'));
$values = (array) $data;
foreach ($data->getClass()->getFields() as $field) {
$m = $field->getModifiers();
if ($m & MODIFIER_STATIC) {
continue;
} else {
if ($m & MODIFIER_PUBLIC) {
$name = $field->getName();
} else {
if ($m & MODIFIER_PROTECTED) {
$name = "*" . $field->getName();
} else {
if ($m & MODIFIER_PRIVATE) {
$name = "" . array_search($field->getDeclaringClass()->getName(), xp::$cn, TRUE) . "" . $field->getName();
}
}
}
}
$member = $n->addChild(new Node('member'));
$member->addChild(new Node('name', $field->getName()));
$member->addChild($this->_marshall($values[$name]));
}
return $value;
}
}
}
switch (xp::typeOf($data)) {
case 'integer':
$value->addChild(new Node('int', $data));
break;
case 'boolean':
$value->addChild(new Node('boolean', (string) (int) $data));
break;
case 'double':
case 'float':
$value->addChild(new Node('double', $data));
break;
case 'array':
if ($this->_isVector($data)) {
$n = $value->addChild(new Node('array'))->addChild(new Node('data'));
for ($i = 0, $s = sizeof($data); $i < $s; $i++) {
$n->addChild($this->_marshall($data[$i]));
}
} else {
$n = $value->addChild(new Node('struct'));
foreach ($data as $name => $v) {
$member = $n->addChild(new Node('member'));
$member->addChild(new Node('name', $name));
$member->addChild($this->_marshall($v));
}
}
break;
case 'string':
$value->addChild(new Node('string', $data));
break;
case 'NULL':
$value->addChild(new Node('nil'));
break;
default:
throw new IllegalArgumentException('Cannot serialize data of type "' . xp::typeOf($data) . '"');
}
return $value;
}
示例13: addAChildToANode
/**
* @test
*/
public function addAChildToANode()
{
$node = new Node(array('id' => 100));
$child = new Node(array('id' => 200));
$node->addChild($child);
$childrenProperty = new \ReflectionProperty($node, 'children');
$childrenProperty->setAccessible(true);
$this->assertSame(array($child), $childrenProperty->getValue($node));
$parentProperty = new \ReflectionProperty($child, 'parent');
$parentProperty->setAccessible(true);
$this->assertSame($node, $parentProperty->getValue($child));
$propertiesProperty = new \ReflectionProperty($child, 'properties');
$propertiesProperty->setAccessible(true);
$this->assertSame(array('id' => 200, 'parent' => 100), $propertiesProperty->getValue($child));
}
示例14: addWebdavObject
/**
* Apply an WebdavObject
*
* @param org.webdav.WebdavObject o
* @param org.webdav.xml.WebdavPropFindRequest request
*/
public function addWebdavObject($o)
{
// Get the property lists
$reqprops = $request->getProperties();
// properties requested
$propsList = $o->getProperties();
// properties available
// Create the result nodes (for found and not found properties)
$found_stat = new Node('D:propstat');
$found_props = $found_stat->addChild(new Node('D:prop'));
$notfound_stat = new Node('D:propstat');
$notfound_props = $notfound_stat->addChild(new Node('D:prop'));
$stdprops = array();
// Always add the Resource type
$rt = $found_props->addChild(new Node('D:resourcetype'));
// Content type/length via resourceType
if (NULL !== $o->resourceType) {
$rt->addChild(new Node('D:' . $o->resourceType));
$stdprops[] = 'resourcetype';
}
// lockingpops, wenn POPERTY_ALL
if (WEBDAV_COLLECTION != $o->resourceType and (empty($reqprops) or !empty($reqprops['supportedlock']))) {
$lock = $found_props->addChild(new Node('D:supportedlock'));
$l1 = $lock->addChild(new Node('D:lockentry'));
$l2 = $l1->addChild(new Node('D:lockscope'));
$l2->addChild(new Node('D:exclusive'));
$l2 = $l1->addChild(new Node('D:locktype'));
$l2->addChild(new Node('D:write'));
$l1 = $lock->addChild(new Node('D:lockentry'));
$l2 = $l1->addChild(new Node('D:lockscope'));
$l2->addChild(new Node('D:shared'));
$l2 = $l1->addChild(new Node('D:locktype'));
$l2->addChild(new Node('D:write'));
$stdprops[] = 'supportedlock';
}
// lock discovery
if (empty($reqprops) or !empty($reqprops['lockdiscovery'])) {
$lkif = $found_props->addChild(new Node('D:lockdiscovery'));
$lockinfos = $o->getLockInfo();
if ($lockinfos) {
for ($t = 0; $t < sizeof($lockinfos); $t++) {
$lockinfo = $lockinfos[$t];
if (empty($lockinfo['type']) or empty($lockinfo['scope'])) {
continue;
}
$ak = $lkif->addChild(new Node('D:activelock'));
$l = $ak->addChild(new Node('D:locktype'));
$l->addChild(new Node('D:' . $lockinfo['type']));
$l = $ak->addChild(new Node('D:lockscope'));
$l->addChild(new Node('D:' . $lockinfo['scope']));
$l = $ak->addChild(new Node('D:owner', $lockinfo['owner']));
$l = $ak->addChild(new Node('D:timeout', $lockinfo['timeout']));
$l = $ak->addChild(new Node('D:locktoken'));
$l->addChild(new Node('D:href', $lockinfo['token']));
$l = $ak->addChild(new Node('D:depth', $lockinfo['depth']));
$stdprops[] = 'lockdiscovery';
}
}
}
// properties which we always know
// get* on collection is not defined!
foreach ($reqprops == NULL ? $propsList : $reqprops as $property) {
$name = $property->getName();
if (in_array($name, $stdprops)) {
continue;
}
if ($found = isset($propsList[$name])) {
$property = $propsList[$name];
}
$attr = $property->getAttributes();
$nsname = $property->getNamespaceName();
$nsprefix = $property->getNamespacePrefix();
$stdprop = $nsname == 'DAV:';
if ($stdprop) {
$name = 'D:' . $name;
} else {
if ($nsname) {
$attr['xmlns' . (!empty($nsprefix) ? ':' . $nsprefix : '')] = $nsname;
if (!empty($nsprefix)) {
$name = $nsprefix . ':' . $name;
}
}
}
if ($found) {
$n = $found_props->addChild(new Node($name, $this->encode($property->toString()), $attr));
} else {
$n = $notfound_props->addChild(new Node($name, $this->encode($property->toString()), $attr));
}
}
// Build result (href, properties, status, ...)
$this->root->addChild(new Node('D:href', $request->encodePath($o->getHref())));
$found_stat->addChild(new Node('D:status', 'HTTP/1.1 200 OK'));
$this->root->addChild($found_stat);
if (!empty($notfound_props->children)) {
//.........这里部分代码省略.........
示例15: groupNode
/**
* Recursively groups tree nodes given a separator
*
* @param Node $node The node to group
*
* @return void
*/
public function groupNode($node)
{
if ($node->type != Node::CONTAINER || $GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']) {
return;
}
$separators = array();
if (is_array($node->separator)) {
$separators = $node->separator;
} else {
if (strlen($node->separator)) {
$separators[] = $node->separator;
}
}
$prefixes = array();
if ($node->separator_depth > 0) {
foreach ($node->children as $child) {
$prefix_pos = false;
foreach ($separators as $separator) {
$sep_pos = strpos($child->name, $separator);
if ($sep_pos != false && $sep_pos != strlen($child->name) && $sep_pos != 0 && ($prefix_pos == false || $sep_pos < $prefix_pos)) {
$prefix_pos = $sep_pos;
}
}
if ($prefix_pos !== false) {
$prefix = substr($child->name, 0, $prefix_pos);
if (!isset($prefixes[$prefix])) {
$prefixes[$prefix] = 1;
} else {
$prefixes[$prefix]++;
}
}
//Bug #4375: Check if prefix is the name of a DB, to create a group.
foreach ($node->children as $child) {
if (array_key_exists($child->name, $prefixes)) {
$prefixes[$child->name]++;
}
}
}
//Check if prefix is the name of a DB, to create a group.
foreach ($node->children as $child) {
if (array_key_exists($child->name, $prefixes)) {
$prefixes[$child->name]++;
}
}
}
foreach ($prefixes as $key => $value) {
if ($value == 1) {
unset($prefixes[$key]);
}
}
if (count($prefixes)) {
$groups = array();
foreach ($prefixes as $key => $value) {
$groups[$key] = new Node($key, Node::CONTAINER, true);
$groups[$key]->separator = $node->separator;
$groups[$key]->separator_depth = $node->separator_depth - 1;
$groups[$key]->icon = '';
if (PMA_Util::showIcons('TableNavigationLinksMode')) {
$groups[$key]->icon = PMA_Util::getImage('b_group.png');
}
$groups[$key]->pos2 = $node->pos2;
$groups[$key]->pos3 = $node->pos3;
if ($node instanceof Node_Table_Container || $node instanceof Node_View_Container) {
$tblGroup = '&tbl_group=' . urlencode($key);
$groups[$key]->links = array('text' => $node->links['text'] . $tblGroup, 'icon' => $node->links['icon'] . $tblGroup);
}
$node->addChild($groups[$key]);
foreach ($separators as $separator) {
// FIXME: this could be more efficient
foreach ($node->children as $child) {
$name_substring = substr($child->name, 0, strlen($key) + strlen($separator));
if ($name_substring != $key . $separator && $child->name != $key || $child->type != Node::OBJECT) {
continue;
}
$class = get_class($child);
$new_child = PMA_NodeFactory::getInstance($class, substr($child->name, strlen($key) + strlen($separator)));
$new_child->real_name = $child->real_name;
$new_child->icon = $child->icon;
$new_child->links = $child->links;
$new_child->pos2 = $child->pos2;
$new_child->pos3 = $child->pos3;
$groups[$key]->addChild($new_child);
foreach ($child->children as $elm) {
$new_child->addChild($elm);
}
$node->removeChild($child->name);
}
}
}
foreach ($prefixes as $key => $value) {
$this->groupNode($groups[$key]);
$groups[$key]->classes = "navGroup";
}
//.........这里部分代码省略.........