/** * {@inheritDoc} */ 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); } usort($filtered, $next); } $offset = $criteria->getFirstResult(); $length = $criteria->getMaxResults(); if ($offset || $length) { $filtered = array_slice($filtered, (int) $offset, $length); } return new static($filtered); }
/** * Select all elements from a selectable that match the criteria and * return a new collection containing these elements. * * @param Criteria $criteria * @return Collection2 */ public function matching(Criteria $criteria) { $this->initialize(); $expr = $criteria->getWhereExpression(); $filtered = $this->entities; if ($expr) { $visitor = new ClosureExpressionVisitor(); $filter = $visitor->dispatch($expr); $filtered = array_filter($filtered, $filter); } if (null !== ($orderings = $criteria->getOrderings())) { $next = null; foreach (array_reverse($orderings) as $field => $ordering) { $next = ClosureExpressionVisitor::sortByField($field, $ordering == 'DESC' ? -1 : 1, $next); } usort($filtered, $next); } $offset = $criteria->getFirstResult(); $length = $criteria->getMaxResults(); if ($offset || $length) { $filtered = array_slice($filtered, (int) $offset, $length); } return new ArrayCollection($filtered); }