/** * Attach a child node * * @param \Zend\Server\Reflection\Node $node * @return void */ public function attachChild(Node $node) { $this->children[] = $node; if ($node->getParent() !== $this) { $node->setParent($this); } }
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; }
public function addChild(Node $n = null) { if ($n === null) { $n = new Node(); } $this->children[] = $n; $n->setParent($this); $n->setTree($this->tree); return $n; }
$parsed = str_replace("((", "( (", $parsed); $parsed = str_replace("))", ") )", $parsed); $parsed = str_replace("))", ") )", $parsed); $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); }
/** * @param \Herbie\Node $child */ public function addChild(Node $child) { $child->setParent($this); $this->children[] = $child; }
/** * Add a node * * @param Node $node * @param int|callable $cost * @return Node */ public function addNode(Node $node, $cost = 0) { $arc = new Arc($this, $node, $cost); $this->arcs[] = $arc; $node->setParent($this); $this->nodes[] = $node; return $node; }
public function removeChild(Node $child) { $this->children = array_values(array_filter($this->children, function ($currentChild) use($child) { return $currentChild !== $child; })); $child->setParent(null); return $child; }
/** * Adds a child to this node * * @param Node $node The child to add * @return Node Returns this for chaining */ public function addChild(Node $node) { $node->setParent($this); $this->children[] = $node; return $this; }
/** * move the node within the current schema * * @param Node $node * @param Node $parent * * @return $this */ public function moveNode(Node $node, Node $parent) { $node->setParent($parent)->updateId(); $this->idList[$node->id] = $node; return $this; }
/** * @expectedException \InvalidArgumentException */ public function testSetParentOnItself() { $node = new Node(); $node->setParent($node); }
function addChild(Node $node) { $this->children[$node->name] = $node; $node->setParent($this); }
/** * Add a node as child of this node. * * @param Node $child * @return $this */ public function addChild(Node $child) { $this->children[] = $child; $child->setParent($this); return $this; }