Zest
Fast, lightweight, extensible CSS selector engine for PHP
|
Zest.php (https://github.com/wikimedia/zest.php) Copyright (c) 2019, C. More...
Public Member Functions | |
array< DOMElement > | getElementsById ( $context, string $id, array $opts=[]) |
Get descendants by ID. | |
array< DOMElement > | getElementsByTagName ( $context, string $tagName, array $opts=[]) |
Get descendants by tag name. | |
addSelector0 (string $key, callable $func) | |
Add a custom selector that takes no parameters. | |
addSelector1 (string $key, callable $func) | |
Add a custom selector that takes 1 parameter, which is passed as a string. | |
addOperator (string $key, callable $func) | |
Add a custom operator. | |
addCombinator (string $key, callable $func) | |
Add a custom combinator. | |
DOMElement[] | find (string $sel, $context, array $opts=[]) |
Find elements matching a CSS selector underneath $context. | |
bool | matches ( $el, string $sel, array $opts=[]) |
Determine whether an element matches the given selector. | |
__construct () | |
Create a new instance of Zest. | |
Static Public Member Functions | |
static | initRules () |
Protected Member Functions | |
array< DOMElement > | getElementsByClassName ( $context, string $className, $opts) |
Clients can subclass and override this to provide a more efficient implementation if one is available. | |
Throwable | newBadSelectorException (string $msg) |
Allow customization of the exception thrown for a bad selector. | |
bool | isStandardsMode ( $context, array $opts) |
Allow subclasses to force Zest into "standards mode" (or not). | |
Zest.php (https://github.com/wikimedia/zest.php) Copyright (c) 2019, C.
Scott Ananian. (MIT licensed) PHP port based on:
Zest (https://github.com/chjj/zest) A css selector engine. Copyright (c) 2011-2012, Christopher Jeffrey. (MIT Licensed) Domino version based on Zest v0.1.3 with bugfixes applied.
Wikimedia\Zest\ZestInst::__construct | ( | ) |
Create a new instance of Zest.
Custom combinators and selectors registered for each instance of Zest do not bleed over into other instances.
Wikimedia\Zest\ZestInst::addCombinator | ( | string | $key, |
callable | $func ) |
Add a custom combinator.
string | $key | Name of the combinator |
callable(callable(DOMNode,array):bool):(callable(DOMNode,array):(?DOMNode)) | $func The combinator match function |
Wikimedia\Zest\ZestInst::addOperator | ( | string | $key, |
callable | $func ) |
Add a custom operator.
string | $key | Name of the operator |
callable(string,string):bool | $func The operator match function |
Wikimedia\Zest\ZestInst::addSelector0 | ( | string | $key, |
callable | $func ) |
Add a custom selector that takes no parameters.
string | $key | Name of the selector |
callable(DOMNode,array):bool | $func The selector match function |
Wikimedia\Zest\ZestInst::addSelector1 | ( | string | $key, |
callable | $func ) |
Add a custom selector that takes 1 parameter, which is passed as a string.
string | $key | Name of the selector |
callable(string,ZestInst):(callable(DOMNode,array):bool)|callable(string):(callable(DOMNode,array):bool) | $func The selector match function |
DOMElement[] Wikimedia\Zest\ZestInst::find | ( | string | $sel, |
$context, | |||
array | $opts = [] ) |
Find elements matching a CSS selector underneath $context.
This search is exclusive; that is, ‘find(’:scope', ...)returns no matches, although
:scope *` would return matches.
string | $sel | The CSS selector string |
DOMDocument | DOMDocumentFragment | DOMElement | $context | The scoping root for the search |
array | $opts | Additional match-context options (optional) |
|
protected |
Clients can subclass and override this to provide a more efficient implementation if one is available.
This is an exclusive query; that is, $context should never be included among the results.
DOMDocument | DOMDocumentFragment | DOMElement | $context | |
string | $className | |
array | $opts |
array< DOMElement > Wikimedia\Zest\ZestInst::getElementsById | ( | $context, | |
string | $id, | ||
array | $opts = [] ) |
Get descendants by ID.
The PHP DOM doesn't provide this method for DOMElement, and the implementation in DOMDocument is broken.
Further, the web spec only provides for returning a single element here. This function can support returning all of the matches for a given ID, if the underlying DOM implementation supports this.
This is an exclusive query; that is, $context should never be included among the results.
Although a getElementsById
key can be passed in the options array to override the default implementation, for efficiency it is recommended that clients subclass ZestInst and override this entire method if they can provide an efficient id index.
DOMDocument | DOMDocumentFragment | DOMElement | $context | The scoping root for the search |
string | $id | |
array | $opts | Additional match-context options (optional) |
array< DOMElement > Wikimedia\Zest\ZestInst::getElementsByTagName | ( | $context, | |
string | $tagName, | ||
array | $opts = [] ) |
Get descendants by tag name.
The PHP DOM doesn't provide this method for DOMElement, and the implementation in DOMDocument has performance issues.
This is an exclusive query; that is, $context should never be included among the results.
Clients can subclass and override this to provide a more efficient implementation if one is available.
DOMDocument | DOMDocumentFragment | DOMElement | $context | |
string | $tagName | |
array | $opts | Additional match-context options (optional) |
|
protected |
Allow subclasses to force Zest into "standards mode" (or not).
The default implementation looks for a 'standardsMode' key in the option and if that is not present switches to standards mode if the ownerDocument of the given node is not a \DOMDocument.
DOMNode | $context | a context node |
array | $opts | The zest options array pased to ::find, ::matches, etc |
bool Wikimedia\Zest\ZestInst::matches | ( | $el, | |
string | $sel, | ||
array | $opts = [] ) |
Determine whether an element matches the given selector.
This test is inclusive; that is, ‘matches($el, ’:scope')` returns true.
DOMNode | $el | The element to be tested |
string | $sel | The CSS selector string |
array | $opts | Additional match-context options (optional) |
|
protected |
Allow customization of the exception thrown for a bad selector.
string | $msg | Description of the failure |