Overview

Namespaces

  • Pharborist
    • Constants
    • ControlStructures
    • Exceptions
    • Functions
    • Generators
    • Namespaces
    • Objects
    • Operators
    • Types
    • Variables

Classes

  • ArrayLookupNode
  • BacktickNode
  • BlankStatementNode
  • CommaListNode
  • CommentNode
  • DocCommentNode
  • EchoStatementNode
  • EchoTagStatementNode
  • ExpressionStatementNode
  • Filter
  • Formatter
  • FormatterFactory
  • LineCommentBlockNode
  • Node
  • NodeCollection
  • OperatorFactory
  • ParenthesisNode
  • ParentNode
  • Parser
  • PartialCommentNode
  • PartialNode
  • RootNode
  • SourceDiscovery
  • SourcePosition
  • SplatNode
  • StatementBlockNode
  • StatementNode
  • TemplateNode
  • Token
  • TokenIterator
  • Tokenizer
  • TokenNode
  • UnsetStatementNode
  • VisitorBase
  • WhitespaceNode

Interfaces

  • ExpressionNode
  • NodeInterface
  • ParentNodeInterface
  • ParserException
  • VisitorInterface

Traits

  • DocCommentTrait
  • ParenTrait
  • UncommentTrait
  • Overview
  • Namespace
  • Class

Class Node

A node in the PHP syntax tree.

Pharborist\Node implements Pharborist\NodeInterface

Direct known subclasses

Pharborist\ParentNode, Pharborist\TokenNode

Indirect known subclasses

Pharborist\ArrayLookupNode, Pharborist\BacktickNode, Pharborist\Constants\FileMagicConstantNode, Pharborist\Operators\BitwiseShiftLeftNode, Pharborist\Operators\BitwiseShiftRightAssignNode, Pharborist\Operators\BitwiseShiftRightNode, Pharborist\Operators\BitwiseXorAssignNode, Pharborist\Operators\BitwiseXorNode, Pharborist\Operators\BooleanAndNode, Pharborist\Operators\BooleanCastNode, Pharborist\Operators\BooleanNotNode, Pharborist\Operators\BooleanOrNode, Pharborist\Operators\CastNode, Pharborist\Constants\FunctionMagicConstantNode, Pharborist\Operators\CloneNode, Pharborist\Operators\ConcatAssignNode, Pharborist\Operators\ConcatNode, Pharborist\Operators\DivideAssignNode, Pharborist\Operators\DivideNode, Pharborist\Operators\ElvisNode, Pharborist\Operators\EqualNode, Pharborist\Operators\FloatCastNode, Pharborist\Operators\GreaterThanNode, Pharborist\Operators\GreaterThanOrEqualToNode, Pharborist\Constants\LineMagicConstantNode, Pharborist\Operators\IdenticalNode, Pharborist\Operators\InstanceOfNode, Pharborist\Operators\IntegerCastNode, Pharborist\Operators\LessThanNode, Pharborist\Operators\LessThanOrEqualToNode, Pharborist\Operators\LogicalAndNode, Pharborist\Operators\LogicalOrNode, Pharborist\Operators\LogicalXorNode, Pharborist\Operators\ModulusAssignNode, Pharborist\Operators\ModulusNode, Pharborist\Constants\MethodMagicConstantNode, Pharborist\Operators\MultiplyAssignNode, Pharborist\Operators\MultiplyNode, Pharborist\Operators\NegateNode, Pharborist\Operators\NotEqualNode, Pharborist\Operators\NotIdenticalNode, Pharborist\Operators\ObjectCastNode, Pharborist\Operators\PlusNode, Pharborist\Operators\PostDecrementNode, Pharborist\Operators\PostIncrementNode, Pharborist\Operators\PowerAssignNode, Pharborist\Constants\NamespaceMagicConstantNode, Pharborist\Operators\PowerNode, Pharborist\Operators\PreDecrementNode, Pharborist\Operators\PreIncrementNode, Pharborist\Operators\PrintNode, Pharborist\Operators\StringCastNode, Pharborist\Operators\SubtractAssignNode, Pharborist\Operators\SubtractNode, Pharborist\Operators\SuppressWarningNode, Pharborist\Operators\TernaryOperationNode, Pharborist\Operators\UnaryOperationNode, Pharborist\Constants\TraitMagicConstantNode, Pharborist\Operators\UnsetCastNode, Pharborist\ParenthesisNode, Pharborist\PartialCommentNode, Pharborist\PartialNode, Pharborist\RootNode, Pharborist\SplatNode, Pharborist\StatementBlockNode, Pharborist\StatementNode, Pharborist\TemplateNode, Pharborist\Types\ArrayNode, Pharborist\ControlStructures\BreakStatementNode, Pharborist\Types\ArrayPairNode, Pharborist\Types\BooleanNode, Pharborist\Types\FalseNode, Pharborist\Types\FloatNode, Pharborist\Types\HeredocNode, Pharborist\Types\IntegerNode, Pharborist\Types\InterpolatedStringNode, Pharborist\Types\NullNode, Pharborist\Types\StringNode, Pharborist\Types\StringVariableNode, Pharborist\ControlStructures\CaseNode, Pharborist\Types\TrueNode, Pharborist\UnsetStatementNode, Pharborist\Variables\CompoundVariableNode, Pharborist\Variables\GlobalStatementNode, Pharborist\Variables\ReferenceVariableNode, Pharborist\Variables\StaticVariableNode, Pharborist\Variables\StaticVariableStatementNode, Pharborist\Variables\VariableNode, Pharborist\Variables\VariableVariableNode, Pharborist\WhitespaceNode, Pharborist\ControlStructures\ContinueStatementNode, Pharborist\ControlStructures\DeclareDirectiveNode, Pharborist\BlankStatementNode, Pharborist\ControlStructures\DeclareNode, Pharborist\ControlStructures\DefaultNode, Pharborist\ControlStructures\DoWhileNode, Pharborist\ControlStructures\ElseIfNode, Pharborist\ControlStructures\ExitNode, Pharborist\ControlStructures\ForeachNode, Pharborist\ControlStructures\ForNode, Pharborist\ControlStructures\GotoLabelNode, Pharborist\ControlStructures\GotoStatementNode, Pharborist\ControlStructures\IfNode, Pharborist\CommaListNode, Pharborist\ControlStructures\ImportNode, Pharborist\ControlStructures\IncludeNode, Pharborist\ControlStructures\IncludeOnceNode, Pharborist\ControlStructures\RequireNode, Pharborist\ControlStructures\RequireOnceNode, Pharborist\ControlStructures\ReturnStatementNode, Pharborist\ControlStructures\SwitchNode, Pharborist\ControlStructures\WhileNode, Pharborist\DocCommentNode, Pharborist\EchoStatementNode, Pharborist\CommentNode, Pharborist\EchoTagStatementNode, Pharborist\Exceptions\CatchNode, Pharborist\Exceptions\ThrowStatementNode, Pharborist\Exceptions\TryCatchNode, Pharborist\ExpressionStatementNode, Pharborist\Functions\AnonymousFunctionNode, Pharborist\Functions\CallbackCallNode, Pharborist\Functions\CallNode, Pharborist\Functions\DefineNode, Pharborist\Functions\EmptyNode, Pharborist\Constants\ClassMagicConstantNode, Pharborist\Functions\EvalNode, Pharborist\Functions\FunctionCallNode, Pharborist\Functions\FunctionDeclarationNode, Pharborist\Functions\HaltCompilerNode, Pharborist\Functions\IssetNode, Pharborist\Functions\ListNode, Pharborist\Functions\ParameterNode, Pharborist\Functions\UnsetNode, Pharborist\Generators\YieldNode, Pharborist\Generators\YieldStatementNode, Pharborist\Constants\ConstantDeclarationNode, Pharborist\LineCommentBlockNode, Pharborist\Namespaces\NameNode, Pharborist\Namespaces\NamespaceNode, Pharborist\Namespaces\UseDeclarationBlockNode, Pharborist\Namespaces\UseDeclarationNode, Pharborist\Namespaces\UseDeclarationStatementNode, Pharborist\Objects\ClassConstantLookupNode, Pharborist\Objects\ClassMemberListNode, Pharborist\Objects\ClassMemberLookupNode, Pharborist\Objects\ClassMemberNode, Pharborist\Constants\ConstantDeclarationStatementNode, Pharborist\Objects\ClassMethodCallNode, Pharborist\Objects\ClassMethodNode, Pharborist\Objects\ClassNameScalarNode, Pharborist\Objects\ClassNode, Pharborist\Objects\ClassStatementNode, Pharborist\Objects\InterfaceMethodNode, Pharborist\Objects\InterfaceNode, Pharborist\Objects\NameExpressionNode, Pharborist\Objects\NewNode, Pharborist\Objects\ObjectMethodCallNode, Pharborist\Constants\ConstantNode, Pharborist\Objects\ObjectPropertyNode, Pharborist\Objects\SingleInheritanceNode, Pharborist\Objects\TraitAdaptationStatementNode, Pharborist\Objects\TraitAliasNode, Pharborist\Objects\TraitMethodReferenceNode, Pharborist\Objects\TraitNode, Pharborist\Objects\TraitPrecedenceNode, Pharborist\Objects\TraitUseNode, Pharborist\Operators\AddAssignNode, Pharborist\Operators\AddNode, Pharborist\Constants\DirMagicConstantNode, Pharborist\Operators\ArrayCastNode, Pharborist\Operators\AssignNode, Pharborist\Operators\AssignReferenceNode, Pharborist\Operators\BinaryOperationNode, Pharborist\Operators\BitwiseAndAssignNode, Pharborist\Operators\BitwiseAndNode, Pharborist\Operators\BitwiseNotNode, Pharborist\Operators\BitwiseOrAssignNode, Pharborist\Operators\BitwiseOrNode, Pharborist\Operators\BitwiseShiftLeftAssignNode
Abstract
Namespace: Pharborist
Located at Node.php
Methods summary
public Pharborist\ParentNode
# parent( callable $callback = NULL )

Get the parent node.

Get the parent node.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\ParentNode

Implementation of

Pharborist\NodeInterface::parent()
public Pharborist\NodeCollection
# parents( callable $callback = NULL )

Get the ancestors of this node.

Get the ancestors of this node.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::parents()
public Pharborist\NodeCollection
# parentsUntil( callable $callback, boolean $inclusive = FALSE )

Get ancestors up to the node matched by callback.

Get ancestors up to the node matched by callback.

Parameters

$callback
Callback to test for match.
$inclusive
TRUE to include the node matched by callback.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::parentsUntil()
public Pharborist\Node
# closest( callable $callback )

Get the first node matched by the callback by testing this node and traversing up through its ancestors in the tree.

Get the first node matched by the callback by testing this node and traversing up through its ancestors in the tree.

Parameters

$callback
Callback to test for match.

Returns

Pharborist\Node

Implementation of

Pharborist\NodeInterface::closest()
public Pharborist\Node
# furthest( callable $callback )

Get the last node matched by the callback by testing this node and traversing up through its ancestors in the tree.

Get the last node matched by the callback by testing this node and traversing up through its ancestors in the tree.

Parameters

$callback
Callback to test for match.

Returns

Pharborist\Node

Implementation of

Pharborist\NodeInterface::furthest()
public integer
# index( )

Get the position of the element relative to its sibling elements.

Get the position of the element relative to its sibling elements.

Returns

integer

Implementation of

Pharborist\NodeInterface::index()
public Pharborist\Node
# previous( callable $callback = NULL )

Get the previous sibling.

Get the previous sibling.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\Node

Implementation of

Pharborist\NodeInterface::previous()
public Pharborist\NodeCollection
# previousAll( callable $callback = NULL )

Get the previous siblings of this node.

Get the previous siblings of this node.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::previousAll()
public Pharborist\NodeCollection
# previousUntil( callable $callback, boolean $inclusive = FALSE )

Get all the preceding siblings up to but not including the match.

Get all the preceding siblings up to but not including the match.

Parameters

$callback
Callback to test for match.
$inclusive
TRUE to include the node matched by callback.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::previousUntil()
public Pharborist\Node
# next( callable $callback = NULL )

Get the next immediate sibling.

Get the next immediate sibling.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\Node

Implementation of

Pharborist\NodeInterface::next()
public Pharborist\NodeCollection
# nextAll( callable $callback = NULL )

Get all the following siblings.

Get all the following siblings.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::nextAll()
public Pharborist\NodeCollection
# nextUntil( callable $callback, boolean $inclusive = FALSE )

Get all the following siblings up to but not including the match.

Get all the following siblings up to but not including the match.

Parameters

$callback
Callback to test for match.
$inclusive
TRUE to include the node matched by callback.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::nextUntil()
public Pharborist\NodeCollection
# siblings( callable $callback = NULL )

Get the siblings.

Get the siblings.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection

Implementation of

Pharborist\NodeInterface::siblings()
public
# insertBefore( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $targets )

Insert this node before targets.

Insert this node before targets.

Parameters

$targets
Nodes to insert before.

Returns


$this

Implementation of

Pharborist\NodeInterface::insertBefore()
public
# before( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Insert nodes before this node.

Insert nodes before this node.

Parameters

$nodes
Nodes to insert.

Returns


$this

Implementation of

Pharborist\NodeInterface::before()
public
# insertAfter( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $targets )

Insert this node after targets.

Insert this node after targets.

Parameters

$targets
Nodes to insert after.

Returns


$this

Implementation of

Pharborist\NodeInterface::insertAfter()
public
# after( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Insert nodes after this node.

Insert nodes after this node.

Parameters

$nodes
Nodes to insert.

Returns


$this

Implementation of

Pharborist\NodeInterface::after()
public
# remove( )

Remove this node from its parent.

Remove this node from its parent.

Returns


$this

Implementation of

Pharborist\NodeInterface::remove()
public
# replaceWith( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection|callable $nodes )

Replace this node with another node.

Replace this node with another node.

Parameters

$nodes
$node Replacement node.

Returns


$this

Implementation of

Pharborist\NodeInterface::replaceWith()
public
# replaceAll( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $targets )

Replace nodes with this node.

Replace nodes with this node.

Parameters

$targets
Nodes to replace.

Returns


$this

Implementation of

Pharborist\NodeInterface::replaceAll()
public
# swapWith( Pharborist\Node $replacement )

Swap this node with another.

Swap this node with another.

Parameters

$replacement
$node Node to swap with.

Returns


$this

Implementation of

Pharborist\NodeInterface::swapWith()
public
# prependTo( Pharborist\ParentNode|Pharborist\ParentNode[]|Pharborist\NodeCollection $targets )

Prepend this node to target.

Prepend this node to target.

Parameters

$targets
Targets to prepend to.

Returns


$this

Implementation of

Pharborist\NodeInterface::prependTo()
public
# appendTo( Pharborist\ParentNode|Pharborist\ParentNode[]|Pharborist\NodeCollection $targets )

Append this node to target.

Append this node to target.

Parameters

$targets
Targets to append to.

Returns


$this

Implementation of

Pharborist\NodeInterface::appendTo()
public string
# sortKey( )

Get a unique key for sorting this node.

Get a unique key for sorting this node.

Used to sort nodes into tree order. That is top to bottom and then left to right.

Returns

string
public boolean
# is( callable|string $test )

Tests this node against a condition.

Tests this node against a condition.

Parameters

$test

Either a callback function to test the node against, or a class name (wrapper around instanceof). Eventually this will accept a callable or a filter query (issue #61).

Returns

boolean

Throws

InvalidArgumentException
public boolean
# isAnyOf( array $tests )

Tests if this node matches any the tests in the array.

Tests if this node matches any the tests in the array.

Parameters

$tests

Returns

boolean
public boolean
# isAllOf( array $tests )

Tests if this node matches all of the tests in the array.

Tests if this node matches all of the tests in the array.

Parameters

$tests

Returns

boolean
public Pharborist\StatementBlockNode|Pharborist\RootNode|null
# getLogicalBlock( )

Returns the code block containing this node. The code block could be a control structure (if statement, for loop, case statement, etc.), a function, a class definition, or the whole syntax tree.

Returns the code block containing this node. The code block could be a control structure (if statement, for loop, case statement, etc.), a function, a class definition, or the whole syntax tree.

Returns

Pharborist\StatementBlockNode|Pharborist\RootNode|null
public static Pharborist\Types\FloatNode|Pharborist\Types\IntegerNode|Pharborist\Types\StringNode|Pharborist\Types\BooleanNode|Pharborist\Types\NullNode|Pharborist\Types\ArrayNode
# fromValue( string|integer|float|boolean|array|null $value )

Creates a Node from a php value.

Creates a Node from a php value.

Parameters

$value
The value to create a node for.

Returns

Pharborist\Types\FloatNode|Pharborist\Types\IntegerNode|Pharborist\Types\StringNode|Pharborist\Types\BooleanNode|Pharborist\Types\NullNode|Pharborist\Types\ArrayNode

Throws

InvalidArgumentException
if $value is not a scalar.
public Pharborist\StatementNode|null
# getStatement( )

Returns the statement (or statement block) which contains this node, if it's part of a statement.

Returns the statement (or statement block) which contains this node, if it's part of a statement.

Returns

Pharborist\StatementNode|null
public Pharborist\RootNode|null
# getRoot( )

Returns the root node if this node belongs to one.

Returns the root node if this node belongs to one.

Returns

Pharborist\RootNode|null

Implementation of

Pharborist\NodeInterface::getRoot()
public
# hasRoot( )

Returns TRUE if this node belongs to a root node.

Returns TRUE if this node belongs to a root node.

Implementation of

Pharborist\NodeInterface::hasRoot()
public Pharborist\TokenNode
# previousToken( )

Returns

Pharborist\TokenNode
public Pharborist\TokenNode
# nextToken( )

Returns

Pharborist\TokenNode
public
# __clone( )
Methods inherited from Pharborist\NodeInterface
getSourcePosition(), getText()
Pharborist API documentation generated by ApiGen