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 NodeCollection

A set of matched nodes.

jQuery like wrapper around Node[] to support Traversing and Manipulation.

Pharborist\NodeCollection implements IteratorAggregate, Countable, ArrayAccess

Direct known subclasses

Pharborist\Functions\ParameterNodeCollection
Namespace: Pharborist
Located at NodeCollection.php
Methods summary
public
# __construct( $nodes = [], $sort = TRUE )
public
# getIterator( )

Implements \IteratorAggregate::getIterator().

Implements \IteratorAggregate::getIterator().

Implementation of

IteratorAggregate::getIterator()
public
# count( )

Implements \Countable::count().

Implements \Countable::count().

Implementation of

Countable::count()
public boolean
# offsetExists( integer $offset )

Implements \ArrayAccess::offsetExists().

Implements \ArrayAccess::offsetExists().

Parameters

$offset

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public Pharborist\Node
# offsetGet( integer $offset )

Implements \ArrayAccess::offsetGet().

Implements \ArrayAccess::offsetGet().

Parameters

$offset

Returns

Pharborist\Node

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( integer $offset, Pharborist\Node $value )

Implements \ArrayAccess::offsetSet().

Implements \ArrayAccess::offsetSet().

Parameters

$offset
$value

Throws

BadMethodCallException

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( integer $offset )

Implements \ArrayAccess::offsetUnset().

Implements \ArrayAccess::offsetUnset().

Parameters

$offset

Throws

BadMethodCallException

Implementation of

ArrayAccess::offsetUnset()
public boolean
# isEmpty( )

Returns if the collection is empty.

Returns if the collection is empty.

Returns

boolean
public boolean
# isNotEmpty( )

Returns if the collection is not empty.

Returns if the collection is not empty.

Returns

boolean
public Pharborist\Node[]
# reverse( )

Get collection in reverse order

Get collection in reverse order

Returns

Pharborist\Node[]
public Pharborist\NodeCollection
# slice( integer $start_index, integer $end_index = NULL )

Reduce the set of matched nodes to a subset specified by a range.

Reduce the set of matched nodes to a subset specified by a range.

Parameters

$start_index
$end_index

Returns

Pharborist\NodeCollection
public Pharborist\NodeCollection
# map( callable $callback )

Creates a new collection by applying a callback to each node in the matched set, like jQuery's .map().

Creates a new collection by applying a callback to each node in the matched set, like jQuery's .map().

Parameters

$callback
The callback to apply, receiving the current node in the set.

Returns

Pharborist\NodeCollection
public mixed
# reduce( callable $callback, mixed $initial = NULL )

Iteratively reduce the collection to a single value using a callback.

Iteratively reduce the collection to a single value using a callback.

Parameters

$callback

Callback function that receives the return value of the previous iteration and the current node in the set being processed.

$initial

The initial value for first iteration, or final result in case of empty collection.

Returns

mixed
Returns the resulting value.
public Pharborist\Node[]
# toArray( )

Returns the raw array of nodes, like jQuery's get() called with no arguments.

Returns the raw array of nodes, like jQuery's get() called with no arguments.

Returns

Pharborist\Node[]
public Pharborist\Node
# get( integer $index )

Get the element at index.

Get the element at index.

Parameters

$index
Index of element to get.

Returns

Pharborist\Node
public integer
# indexOf( callable $callback )

Index of first element that is matched by callback.

Index of first element that is matched by callback.

Parameters

$callback
Callback to test for node match.

Returns

integer
Index of first element that is matched by callback.
public boolean
# is( callable $callback )

Test is any element in collection matches.

Test is any element in collection matches.

Parameters

$callback
Callback to test for node match.

Returns

boolean
TRUE if any element in set of nodes matches.
public Pharborist\NodeCollection
# parent( callable $callback = NULL )

Get the parent of each node in the current set of matched nodes, optionally filtered by a callback.

Get the parent of each node in the current set of matched nodes, optionally filtered by a callback.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get the ancestors of each node in the current set of matched nodes, optionally filtered by a callback.

Get the ancestors of each node in the current set of matched nodes, optionally filtered by a callback.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get ancestors of each node in the current set of matched nodes, up to the node matched by callback.

Get ancestors of each node in the current set of matched nodes, 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
public Pharborist\Node
# closest( callable $callback )

For each node in the collection, get the first node matched by the callback by testing this node and traversing up through its ancestors in the tree.

For each node in the collection, 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
public Pharborist\NodeCollection
# children( callable $callback = NULL )

Get the immediate children of each node in the set of matched nodes.

Get the immediate children of each node in the set of matched nodes.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection
public
# clear( )

Remove all child nodes of the set of matched elements.

Remove all child nodes of the set of matched elements.

Returns


$this
public Pharborist\NodeCollection
# previous( callable $callback = NULL )

Get the immediately preceding sibling of each node in the set of matched nodes. If a callback is provided, it retrieves the next sibling only if the callback returns TRUE.

Get the immediately preceding sibling of each node in the set of matched nodes. If a callback is provided, it retrieves the next sibling only if the callback returns TRUE.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get all preceding siblings of each node in the set of matched nodes, optionally filtered by a callback.

Get all preceding siblings of each node in the set of matched nodes, optionally filtered by a callback.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get all preceding siblings of each node up to the node matched by the callback.

Get all preceding siblings of each node up to the node matched by the callback.

Parameters

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

Returns

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

Get the immediately following sibling of each node in the set of matched nodes. If a callback is provided, it retrieves the next sibling only if the callback returns TRUE.

Get the immediately following sibling of each node in the set of matched nodes. If a callback is provided, it retrieves the next sibling only if the callback returns TRUE.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get all following siblings of each node in the set of matched nodes, optionally filtered by a callback.

Get all following siblings of each node in the set of matched nodes, optionally filtered by a callback.

Parameters

$callback
An optional callback to filter by.

Returns

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

Get all following siblings of each node up to the node matched by the callback.

Get all following siblings of each node up to the node matched by the callback.

Parameters

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

Returns

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

Get the siblings of each node in the set of matched nodes, optionally filtered by a callback.

Get the siblings of each node in the set of matched nodes, optionally filtered by a callback.

Parameters

$callback
An optional callback to filter by.

Returns

Pharborist\NodeCollection
public Pharborist\NodeCollection
# find( callable $callback )

Get the descendants of each node in the current set of matched nodes, filtered by callback.

Get the descendants of each node in the current set of matched nodes, filtered by callback.

Parameters

$callback
Callback to filter by.

Returns

Pharborist\NodeCollection
public Pharborist\NodeCollection
# filter( callable $callback )

Reduce the set of matched nodes to those that pass the callback filter.

Reduce the set of matched nodes to those that pass the callback filter.

Parameters

$callback
Callback to test for match.

Returns

Pharborist\NodeCollection
public Pharborist\NodeCollection
# not( callable $callback )

Remove nodes from the set of matched nodes.

Remove nodes from the set of matched nodes.

Parameters

$callback
Callback to test for match.

Returns

Pharborist\NodeCollection
public Pharborist\NodeCollection
# has( callable $callback )

Reduce the set of matched nodes to those that have a descendant that match.

Reduce the set of matched nodes to those that have a descendant that match.

Parameters

$callback
Callback to test for match.

Returns

Pharborist\NodeCollection
public
# first( )

Reduce the set of matched nodes to the first in the set.

Reduce the set of matched nodes to the first in the set.

public
# last( )

Reduce the set of matched nodes to the last in the set.

Reduce the set of matched nodes to the last in the set.

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

Insert every node in the set of matched nodes before the targets.

Insert every node in the set of matched nodes before the targets.

Parameters

$targets
Nodes to insert before.

Returns


$this
public
# before( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Insert nodes before each node in the set of matched nodes.

Insert nodes before each node in the set of matched nodes.

Parameters

$nodes
Nodes to insert.

Returns


$this
public
# insertAfter( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $targets )

Insert every node in the set of matched nodes after the targets.

Insert every node in the set of matched nodes after the targets.

Parameters

$targets
Nodes to insert after.

Returns


$this
public
# after( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Insert nodes after each node in the set of matched nodes.

Insert nodes after each node in the set of matched nodes.

Parameters

$nodes
Nodes to insert.

Returns


$this
public
# remove( )

Remove the set of matched nodes from the tree.

Remove the set of matched nodes from the tree.

Returns


$this
public
# replaceWith( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Replace each node in the set of matched nodes with the provided new nodes and return the set of nodes that was removed.

Replace each node in the set of matched nodes with the provided new nodes and return the set of nodes that was removed.

Parameters

$nodes
Replacement nodes.

Returns


$this
public
# replaceAll( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $targets )

Replace each target node with the set of matched nodes.

Replace each target node with the set of matched nodes.

Parameters

$targets
Targets to replace.

Returns


$this
public
# add( Pharborist\Node|Pharborist\Node[]|Pharborist\NodeCollection $nodes )

Add nodes to this collection.

Add nodes to this collection.

Parameters

$nodes
Nodes to add to collection.

Returns


$this

Throws

InvalidArgumentException
public static
# addTo( Pharborist\NodeCollection $collection )

Merges the current collection with another one, and returns the other one.

Merges the current collection with another one, and returns the other one.

Parameters

$collection
The destination collection.

Returns

static
public
# each( callable $callback )

Apply callback on each element in the node collection.

Apply callback on each element in the node collection.

Parameters

$callback
Callback to apply on each element.

Returns


$this
public
# __clone( )
Pharborist API documentation generated by ApiGen