Methods Summary | ||
---|---|---|
protected static
|
#
createInvalidContentException( $content )
Create invalid content exception for the specified content.
|
|
protected static
|
#
traverseMatch( SDom\Dom $dom , array $selectorTokens , SDom\Node\NodeInterface $node , SDom\Node\NodeInterface $effectiveRoot )
Traverse the specified node and all of its child nodes recursively (any node type is accepted, but only element
nodes are processed) and match against the specified selector tokens.
Add all nodes that match at least one of the selector tokens to the specified Dom collection and return it.
The supplied $effectiveRoot node will be considered the root of the tree, even if there are more ancestors.
Child nodes will be treated, when matching, as if they don't have a parent node.
|
|
protected static
|
#
findFirstElement( array $nodes )
Loop over the supplied array of nodes and return the first matched element node or NULL.
|
|
protected static
|
#
findFirstInnermostElement( array $nodes , SDom\Node\Element $fallback = NULL )
Loop over the supplied array of nodes and find the first matched element node. If it has child nodes, find the
first matched element child, then recurse until the inner-most element node with no children (element nodes)
is found and return it.
If the array does not contain an element node, return NULL.
|
|
public
|
#
__construct( mixed $content = NULL )
Dom constructor.
Create new collection from the specified content.
If the content is NULL, create empty collection.
If the content is a Dom instance, copy the nodes into the new collection.
If the content is a NodeInterface, add it to the collection.
If the content is a Token, convert it to the corresponding NodeInterface (tree) and add it to the collection.
If the content is a TokenCollection, convert it to NodeInterface instances and add them to the collection.
If the content is a string, parse as HTML and treat as TokenCollection.
Strings with all whitespace produce empty collections. Strings with invalid HTML throw an exception.
|
|
public
|
||
public
|
#
getIterator( )
Return an \ArrayIterator with all nodes wrapped in a Dom instance.
Implementation of |
|
public
|
||
public
|
||
public
|
||
public
|
||
public
|
||
public
|
||
public
|
||
public
|
||
public
|
#
append( $content )
Insert content after all immediate child nodes of each Element node in the collection.
If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
be assigned a new parent node. This means that, if appended to more than one Element node, references to each
appended node will only point to the very first insertion.
E.g. if the same node is appended to two or more Element nodes, its reference will point to the node with the
first Element as parent. Nodes appended to all other Element nodes will be cloned copies. The same rule applies
to child nodes of appended nodes, at any depth, as the whole sub-tree is cloned recursively.
|
|
public
|
#
prepend( $content )
Insert content before all immediate child nodes of each Element node in the collection.
If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
be assigned a new parent node. This means that, if prepended to more than one Element node, references to each
prepended node will only point to the very first insertion.
E.g. if the same node is prepended to two or more Element nodes, its reference will point to the node with the
first Element as parent. Nodes prepended to all other Element nodes will be cloned copies. The same rule applies
to child nodes of prepended nodes, at any depth, as the whole sub-tree is cloned recursively.
If the supplied content resolves to a collection of nodes, they will be prepended as a group, keeping the order.
|
|
public
|
#
before( $content )
Insert content before each Element node in the collection. If an element in the collection does not have a
parent node it will be skipped / ignored.
If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
be assigned a new parent node. This means that, if inserted before more than one Element node, references to
each inserted node will only point to the very first successful insertion.
E.g. if the same node is inserted before two or more Element nodes, its reference will point to the node
inserted before the first eligible Element in the collection (an Element without a parent node is not eligible
and will be ignored). Nodes inserted before all other Element nodes will be cloned copies. The same rule applies
to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
|
|
public
|
#
after( $content )
Insert content after each Element node in the collection. If an element in the collection does not have a
parent node it will be skipped / ignored.
If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
be assigned a new parent node. This means that, if inserted after more than one Element node, references to
each inserted node will only point to the very first successful insertion.
E.g. if the same node is inserted after two or more Element nodes, its reference will point to the node
inserted after the first eligible Element in the collection (an Element without a parent node is not eligible
and will be ignored). Nodes inserted after all other Element nodes will be cloned copies. The same rule applies
to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
|
|
public
|
#
wrap( $content )
Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection.
If the content resolves to a collection of more than one wrapping element node, use only the first one.
If the wrapping element has children use a single-element-per-level sub-tree, where the wrapping element is
the root and may contain one and only one element node, which may contain another one and only one element node
and so on.
Wrap the current collection nodes in clones of this sub-tree as immediate children of the inner-most element
node of the tree. If a node in the collection does not have a parent element, ignore it.
If the wrapping collection does not contain at least one element node, do nothing.
Return the original collection for chaining.
|
|
public
|
||
public
|
||
public
|
||
public
|
#
removeClass( string $className = NULL )
Remove a single class, multiple classes, or all classes from each Element node in the collection.
|
|
public
|
||
public
|
||
public
|
||
public
|
||
public
|
Properties Summary | ||
---|---|---|
protected static
Symfony\Component\CssSelector\Parser\Parser
|
$selectorParser
Singleton instance to a CSS selector parser.
|
#
NULL
|
protected static
SDom\SelectorMatcher
|
$selectorMatcher
Singleton instance to a CSS selector matcher.
|
#
NULL
|
protected static
Kevintweber\HtmlTokenizer\HtmlTokenizer
|
$tokenizer
Singleton instance to an HTML tokenizer.
|
#
NULL
|
protected
\SDom\Node\NodeInterface[]
|
$nodes
Collection of nodes.
|
#
NULL
|