public function ArrayCollection::matching in Plug 7
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
- lib/
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);
}