__clone()
__clone()
Creates a recursive, detached copy of the current node.
Represents a node in a tree-like structure.
All methods should automatically keep a consistent state inside the tree,
e.g. if $someNode->setParent(null)
is done, the previous parent shouldn't have
$someNode
in its children anymore.
hasParent() : \Phug\Ast\NodeInterface
Checks if the current node has a parent-node.
getParent() : \Phug\Ast\NodeInterface|null
Gets the currently associated parent-node.
If the node has no parent, null
is returned.
setParent(\Phug\Ast\NodeInterface $parent) : $this
Sets the nodes parent to a new one.
This will automatically remove it from the old parent, if any, and append it to the new one.
\Phug\Ast\NodeInterface | $parent |
getChildIndex(\Phug\Ast\NodeInterface $child) : integer|false
Returns the numerical index of a child-node.
\Phug\Ast\NodeInterface | $child |
getChildren() : array<mixed,\Phug\Ast\NodeInterface>
Returns an array of child-nodes attached to this node.
setChildren(array<mixed,\Phug\Ast\NodeInterface> $children) : mixed
Replaces all children with new ones.
This will remove all nodes from the current node.
array<mixed,\Phug\Ast\NodeInterface> | $children |
hasChild(\Phug\Ast\NodeInterface $child) : boolean
Checks if this node has a certain child among its children.
\Phug\Ast\NodeInterface | $child |
getChildAt( $index) : \Phug\Ast\NodeInterface
Gets a child at a specified numerical index.
$index |
appendChild(\Phug\Ast\NodeInterface $child) : $this
Appends a child to the child-list.
\Phug\Ast\NodeInterface | $child |
prependChild(\Phug\Ast\NodeInterface $child) : $this
Prepends a child to the child-list.
\Phug\Ast\NodeInterface | $child |
removeChild(\Phug\Ast\NodeInterface $child) : $this
Removes a child from the child-list.
This is detaching. The child and its own child-nodes are still intact, but it's detached from the tree completely and acts as an own root-node.
\Phug\Ast\NodeInterface | $child |
insertBefore(\Phug\Ast\NodeInterface $child, \Phug\Ast\NodeInterface $newChild) : $this
Inserts a child before another child in the child-list.
\Phug\Ast\NodeInterface | $child | |
\Phug\Ast\NodeInterface | $newChild |
insertAfter(\Phug\Ast\NodeInterface $child, \Phug\Ast\NodeInterface $newChild) : $this
Inserts a child after another child in the child-list.
\Phug\Ast\NodeInterface | $child | |
\Phug\Ast\NodeInterface | $newChild |
getPreviousSibling() : \Phug\Ast\NodeInterface
Gets the previous sibling of this child inside its parent.
getNextSibling() : \Phug\Ast\NodeInterface
Gets the next sibling of this child inside its parent.
append(\Phug\Ast\NodeInterface $child) : $this
Appends a child right after this node in its parent.
\Phug\Ast\NodeInterface | $child |
prepend(\Phug\Ast\NodeInterface $child) : $this
Prepends a child before this node in its parent.
\Phug\Ast\NodeInterface | $child |
findChildren(callable $callback, integer $depth = null, integer $level = null) : \Phug\Ast\iterable
Traverses the tree and returns all child elements that match the given callback.
This uses $this->is($callback)
internally.
This method is exclusive, it doesn't include this child in its checks.
callable | $callback | |
integer | $depth | |
integer | $level |
findChildrenArray(callable $callback, integer $depth = null, integer $level = null) : array<mixed,\Phug\Ast\NodeInterface>
Same as `findChildren()`, but returns an iterated array instead of a generator.
callable | $callback | |
integer | $depth | |
integer | $level |
find(callable $callback, integer $depth = null) : \Phug\Ast\iterable
Traverses the tree and returns all child elements that match the given callback.
This uses $this->is($callback)
internally.
This method is inclusive, it includes this child in its checks.
callable | $callback | |
integer | $depth |
findArray(callable $callback, integer $depth = null) : array<mixed,\Phug\Ast\NodeInterface>
Same as `find()`, but returns an iterated array instead of a generator.
callable | $callback | |
integer | $depth |