class Query
Same name in this branch
- 11.1.x vendor/guzzlehttp/psr7/src/Query.php \GuzzleHttp\Psr7\Query
- 11.1.x core/lib/Drupal/Core/Config/Entity/Query/Query.php \Drupal\Core\Config\Entity\Query\Query
- 11.1.x core/lib/Drupal/Core/Entity/Query/Null/Query.php \Drupal\Core\Entity\Query\Null\Query
- 11.1.x core/lib/Drupal/Core/Entity/Query/Sql/Query.php \Drupal\Core\Entity\Query\Sql\Query
- 11.1.x core/lib/Drupal/Core/Entity/KeyValueStore/Query/Query.php \Drupal\Core\Entity\KeyValueStore\Query\Query
- 11.1.x core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query
- 11.1.x core/modules/workspaces/src/EntityQuery/Query.php \Drupal\workspaces\EntityQuery\Query
Nodes query class
@author Marco Marchiò <marco.mm89@gmail.com>
Hierarchy
- class \Peast\Query implements \Peast\IteratorAggregate, \Peast\Countable
Expanded class hierarchy of Query
1 file declares its use of Query
- Program.php in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ Program.php
33 string references to 'Query'
- batch_process in core/
includes/ form.inc - Processes the batch.
- CachePluginBase::cacheGet in core/
modules/ views/ src/ Plugin/ views/ cache/ CachePluginBase.php - Retrieve data from the cache.
- CachePluginBase::cacheSet in core/
modules/ views/ src/ Plugin/ views/ cache/ CachePluginBase.php - Save data to the cache.
- CachePluginBase::generateResultsKey in core/
modules/ views/ src/ Plugin/ views/ cache/ CachePluginBase.php - Calculates and sets a cache ID used for the result cache.
- claro_preprocess_table in core/
themes/ claro/ claro.theme - Implements template_preprocess_HOOK() for table.
File
-
vendor/
mck89/ peast/ lib/ Peast/ Query.php, line 17
Namespace
PeastView source
class Query implements \IteratorAggregate, \Countable {
/**
* Current matches
*
* @var Selector\Matches
*/
protected $matches;
/**
* Options array
*
* @var array
*/
protected $options;
/**
* Class constructor. Available options are:
* - encoding: selectors encoding. If not specified the
* parser will assume UTF-8.
*
* @param Syntax\Node\Program $root Root node
* @param array $options Options array
*/
public function __construct(Syntax\Node\Program $root, $options = array()) {
$this->matches = new Selector\Matches();
$this->matches
->addMatch($root);
$this->options = $options;
}
/**
* Finds nodes matching the given selector starting from the
* current matched nodes, if any, or from the root
*
* @param string $selector Selector
*
* @return $this
*
* @throws Selector\Exception
*/
public function find($selector) {
$parser = new Selector\Parser($selector, $this->options);
$selector = $parser->parse();
$this->matches = $selector->exec($this->matches);
return $this;
}
/**
* Executes the given selector on the current nodes and filters
* out the nodes which don't match
*
* @param string $selector Selector
*
* @return $this
*
* @throws Selector\Exception
*/
public function filter($selector) {
$parser = new Selector\Parser($selector, $this->options);
$selector = $parser->parse(true);
$this->matches
->filter(function ($node, $parent) use ($selector) {
$newMatch = new Selector\Matches();
$newMatch->addMatch($node, $parent);
return $selector->exec($newMatch)
->getMatches();
});
return $this;
}
/**
* Returns the number of matched nodes
*
* @return int
*/
public function count() {
return $this->matches
->count();
}
/**
* Returns the node at the given index
*
* @param int $index Index
*
* @return array
*
* @throws \Exception
*/
public function get($index) {
return $this->matches
->get($index)[0];
}
/**
* Returns the nodes iterator
*
* @return \ArrayIterator
*/
public function getIterator() {
return new \ArrayIterator($this->matches
->getNodes());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Query::$matches | protected | property | Current matches |
Query::$options | protected | property | Options array |
Query::count | public | function | Returns the number of matched nodes |
Query::filter | public | function | Executes the given selector on the current nodes and filters out the nodes which don't match |
Query::find | public | function | Finds nodes matching the given selector starting from the current matched nodes, if any, or from the root |
Query::get | public | function | Returns the node at the given index |
Query::getIterator | public | function | Returns the nodes iterator |
Query::__construct | public | function | Class constructor. Available options are: |