public function ArrayCollection::matching in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php \Doctrine\Common\Collections\ArrayCollection::matching()
Selects all elements from a selectable that match the expression and returns a new collection containing these elements.
Parameters
Criteria $criteria:
Return value
Overrides Selectable::matching
File
- vendor/
doctrine/ collections/ lib/ Doctrine/ Common/ Collections/ ArrayCollection.php, line 359
Class
- ArrayCollection
- An ArrayCollection is a Collection implementation that wraps a regular PHP array.
Namespace
Doctrine\Common\CollectionsCode
public function matching(Criteria $criteria) {
$expr = $criteria
->getWhereExpression();
$filtered = $this->elements;
if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor
->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}
if ($orderings = $criteria
->getOrderings()) {
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1);
}
uasort($filtered, $next);
}
$offset = $criteria
->getFirstResult();
$length = $criteria
->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}
return new static($filtered);
}