$level
$level : integer
Represents a node in the AST the parser generates.
A node has children and always tries to reference its parents
It also has some utility methods to work with those nodes
$parent : \Phug\Ast\NodeInterface
Stores the current parent node of this node.
$children : array<mixed,\Phug\Ast\NodeInterface>
Stores an array of children that are attached to this node.
__construct(\Phug\Lexer\TokenInterface $token = null, \Phug\Util\SourceLocationInterface|null $sourceLocation = null, integer|null $level = null, \Phug\Parser\NodeInterface $parent = null, array<mixed,\Phug\Parser\NodeInterface> $children = null)
Creates a new, detached node without children or a parent.
It can be appended to any node after that
\Phug\Lexer\TokenInterface | $token | the token that created the node |
\Phug\Util\SourceLocationInterface|null | $sourceLocation | |
integer|null | $level | the level of indentation this node is at |
\Phug\Parser\NodeInterface | $parent | the parent of this node |
array<mixed,\Phug\Parser\NodeInterface> | $children | the children of this node |
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 = null) : $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.
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 |
getSourceLocation() : \Phug\Util\SourceLocationInterface|null
getOuterNode() : \Phug\Parser\NodeInterface
getToken() : \Phug\Lexer\TokenInterface
setOuterNode(\Phug\Parser\NodeInterface $node = null) : $this
\Phug\Parser\NodeInterface | $node |
prepareChild(\Phug\Ast\NodeInterface $child)
{@inheritdoc}
\Phug\Ast\NodeInterface | $child |
finishChild(\Phug\Ast\NodeInterface $child)
{@inheritdoc}
\Phug\Ast\NodeInterface | $child |