/** * Find entities by the search criteria * * @param string $class * @param array $criteria * @param array $orderBy * @param int $limit * @param int $skip * * @return \SplObjectStorage */ public function findBy($class, array $criteria, array $orderBy = null, $limit = null, $skip = null) { if (empty($criteria)) { $criteria = null; } $class = $this->identityMap->getClass($class); $metadata = $this->metadataRegistry->getMetadata($class); if ($criteria) { foreach ($criteria as $key => $value) { if (!$metadata->hasProperty($key)) { throw new UnknwonPropertyException(sprintf('Unknown property "%s" for the entity "%s"', $key, $class)); } } } $qb = new QueryBuilder(); if ($metadata instanceof NodeMetadata) { $qb->matchNode('e', $class, $criteria); } else { $qb->addExpr($qb->expr()->matchNode()->relatedTo($qb->expr()->matchRelationship('e', $class, $criteria))); } $qb->toReturn('e'); if ($orderBy !== null) { if (!$metadata->hasProperty($orderBy[0])) { throw new UnknwonPropertyException(sprintf('Unknown property "%s" for the entity "%s"', $key, $class)); } $qb->orderBy(sprintf('e.%s', $orderBy[0]), $orderBy[1]); } if ($skip !== null) { $qb->skip($skip); } if ($limit !== null) { $qb->limit($limit); } return $this->execute($qb->getQuery()); }