/** * @param null $parameters * @param Collection $collection * @return array * @throws \ErrorException */ public static function getResultSet($parameters = null, Collection $collection) { $collectionName = $collection->getCollectionName(); $db = $collection->getConnection(); /** @var \MongoCollection $mCollection */ $mCollection = $db->{$collectionName}; if (isset($parameters['condition']) === true) { $condition = $parameters['condition']; } elseif (isset($parameters['query']) === true) { $condition = $parameters['query']; } else { $condition = []; } if (isset($parameters['fields'])) { $docCursor = $mCollection->find($condition, $parameters['fields']); } else { $docCursor = $mCollection->find($condition); } if (isset($parameters['orderBy']) === true) { $docCursor->sort($parameters['$orderBy']); } if (isset($parameters['limit']) === true) { $docCursor->limit($parameters['limit']); } $docArr = iterator_to_array($docCursor); if (empty($docArr)) { return []; } return static::createObjectFromArr($docArr); }