本文整理汇总了PHP中Node::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getChildren方法的具体用法?PHP Node::getChildren怎么用?PHP Node::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::getChildren方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseNode
/**
* @param \tomzx\HtmlParser\Node $node
* @return array
*/
protected function parseNode(Node $node)
{
$statements = $node->getChildren();
foreach ($node->getChildren() as $child) {
$statements[] = $this->parseNode($child);
}
return $statements;
}
示例2: testChildrenManipulation
public function testChildrenManipulation()
{
$node = new Node();
$node->setChildren(['foo']);
$this->assertCount(1, $node->getChildren());
$this->assertEquals(['foo'], $node->getChildren());
$node->clearChildren();
$this->assertEmpty($node->getChildren());
$node->setChildAtIndex($child1 = new Node(), 2);
$this->assertCount(1, $children = $node->getChildren());
$this->assertEquals($child1, reset($children));
$this->assertEquals(2, key($children));
}
示例3: render
public function render(Node $node)
{
echo str_repeat('--', $node->getDepth()) . $node->getType() . "\n";
foreach ($node->getChildren() as $child) {
$this->render($child);
}
}
示例4: getSiblings
/**
* Returns siblings of the node, optionally including the node itself.
*
* @param bool $includeSelf If true, the node itself will be included in the resulting
* array. In either case, the sort order will be correct.
* This argument is deprecated and will be removed in v2.0
*
* Note: The argument is deprecated and will be removed in version 2; please
* use getSiblingsAndSelf().
*
* @return Node[]
*/
public function getSiblings($includeSelf = false)
{
$siblings = array();
foreach ($this->parent->getChildren() as $child) {
if ($includeSelf || $child->getId() != $this->getId()) {
$siblings[] = $child;
}
}
return $siblings;
}
示例5: getChildren
public function getChildren()
{
if (!$this->areBaseChildrenAccessible()) {
return parent::getChildren();
}
$names = array_keys(array_merge($this->getBaseNode()->getChildren(), $this->childNodes));
$nodes = [];
foreach ($names as $name) {
$nodes[$name] = $this->getChild($name);
}
return $nodes;
}
示例6: 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);
}
}
示例7: find
/**
* Find matching nodes among node children
*
* @param Node $node
*
* @param string $ignoreRoot
*
* @return \USync\AST\NodeInterface[]
*/
public function find(Node $node, $ignoreRoot = true)
{
$ret = [];
if ($ignoreRoot && $node->isRoot()) {
foreach ($node->getChildren() as $child) {
$this->_find($ret, $child);
}
} else {
$this->_find($ret, $node);
}
return $ret;
}
示例8: toArray
/**
* Returns an array representation of the given Node structure.
*
* @param Node $node
*
* @return array
*/
public function toArray(Node $node)
{
return array('name' => $node->getName(), 'value' => $node->getValue(), 'attributes' => $node->getAttributes(), 'children' => array_map(function (Node $child) {
return $this->toArray($child);
}, $node->getChildren()));
}
示例9: addNode
/**
* Create a new node and its children
*
* @param object Hierarchy $newHierarchy
* @param object Node $oldNode
* @param optional object Id $parentId
* @return void
* @access protected
* @since 4/17/08
*/
protected function addNode(Hierarchy $newHierarchy, Node $oldNode, Id $parentId = null)
{
// If it has already been created, get it and try to set its parent
try {
$newNode = $newHierarchy->getNode($oldNode->getId());
if (!is_null($parentId)) {
try {
$newNode->addParent($parentId);
} catch (Exception $e) {
// Do nothing if the child already exists
if ($e->getMessage() != "A child with the given id already exists!") {
throw $e;
}
}
}
} catch (UnknownIdException $e) {
if (is_null($parentId)) {
$newNode = $newHierarchy->createRootNode($oldNode->getId(), $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription());
} else {
$newNode = $newHierarchy->createNode($oldNode->getId(), $parentId, $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription());
}
$this->nodeStatus->updateStatistics();
}
$oldChildren = $oldNode->getChildren();
while ($oldChildren->hasNext()) {
$oldChild = $oldChildren->next();
$this->addNode($newHierarchy, $oldChild, $newNode->getId());
}
}
示例10: getIterator
/**
* @return \RecursiveIteratorIterator
*/
public function getIterator()
{
return new \RecursiveIteratorIterator($this->head->getChildren(), \RecursiveIteratorIterator::SELF_FIRST);
}
示例11: writeType
/**
* Write an individual type to the stream.
*
* @param resource $fPtr Stream pointer
* @param int $tagType Type of tag to write
* @param Node $node Node containing value to write
*
* @return bool
*/
private function writeType($fPtr, $tagType, Node $node)
{
switch ($tagType) {
case Tag::TAG_BYTE:
// Signed byte (8 bit)
return $this->dataHandler->putTAGByte($fPtr, $node->getValue());
case Tag::TAG_SHORT:
// Signed short (16 bit, big endian)
return $this->dataHandler->putTAGShort($fPtr, $node->getValue());
case Tag::TAG_INT:
// Signed integer (32 bit, big endian)
return $this->dataHandler->putTAGInt($fPtr, $node->getValue());
case Tag::TAG_LONG:
// Signed long (64 bit, big endian)
return $this->dataHandler->putTAGLong($fPtr, $node->getValue());
case Tag::TAG_FLOAT:
// Floating point value (32 bit, big endian, IEEE 754-2008)
return $this->dataHandler->putTAGFloat($fPtr, $node->getValue());
case Tag::TAG_DOUBLE:
// Double value (64 bit, big endian, IEEE 754-2008)
return $this->dataHandler->putTAGDouble($fPtr, $node->getValue());
case Tag::TAG_BYTE_ARRAY:
// Byte array
return $this->dataHandler->putTAGByteArray($fPtr, $node->getValue());
case Tag::TAG_STRING:
// String
return $this->dataHandler->putTAGString($fPtr, $node->getValue());
case Tag::TAG_INT_ARRAY:
// Byte array
return $this->dataHandler->putTAGIntArray($fPtr, $node->getValue());
case Tag::TAG_LIST:
// List
if (!($this->dataHandler->putTAGByte($fPtr, $node->getPayloadType()) && $this->dataHandler->putTAGInt($fPtr, count($node->getChildren())))) {
return false;
}
foreach ($node->getChildren() as $childNode) {
if (!$this->writeType($fPtr, $node->getPayloadType(), $childNode)) {
return false;
}
}
return true;
case Tag::TAG_COMPOUND:
// Compound
foreach ($node->getChildren() as $childNode) {
if (!$this->writeTag($fPtr, $childNode)) {
return false;
}
}
if (!$this->writeType($fPtr, Tag::TAG_END, new Node())) {
return false;
}
return true;
case Tag::TAG_END:
// End tag
return is_int(fwrite($fPtr, ""));
}
}
示例12: getChildrenReturnsEmptyArrayWhenNoChildNodesExist
/**
* @test
*/
public function getChildrenReturnsEmptyArrayWhenNoChildNodesExist()
{
$parent = new Node(array('id' => 52));
$this->assertSame(array(), $parent->getChildren());
}