/** * @param $params * @param Collection $collection * @param $connection * @return mixed * @throws \Exception */ protected static function _getResultCursor($params, $collection, $connection) { $source = $collection->getSource(); if (empty($source)) { throw new \Exception('Method getSource() returns empty string'); } /** @var \MongoCollection $mongoCollection */ $mongoCollection = $connection->selectCollection($source); if (!is_object($mongoCollection)) { throw new \Exception('Couldn\'t select mongo collection'); } /** * Convert the string to an array */ if (!isset($params[0])) { if (!isset($params['conditions'])) { $conditions = []; } else { $conditions = $params['conditions']; } } else { $conditions = $params[0]; } if (!is_array($conditions)) { throw new \Exception('Find parameters must be an array'); } /** * Perform the find */ if (isset($params['fields'])) { $documentsCursor = $mongoCollection->find($conditions, $params['fields']); } else { $documentsCursor = $mongoCollection->find($conditions); } /** * Check if a 'limit' clause was defined */ if (isset($params['limit'])) { $documentsCursor->limit($params['limit']); } /** * Check if a 'sort' clause was defined */ if (isset($params['sort'])) { $documentsCursor->sort($params['sort']); } /** * Check if a 'skip' clause was defined */ if (isset($params['skip'])) { $documentsCursor->skip($params['skip']); } /** * If a group of specific fields are requested we use a Phalcon\Mvc\Collection\Document instead */ if (isset($params['fields'])) { $documentsCursor->fields($params['fields']); } return $documentsCursor; }
public function testShouldCheckMappedValues() { $this->assertFalse(Collection::getMapped(false)); $product = new Product(); $product->setName('Product 1'); $product->setPrice(100); $product->setIsActive(true); $product->setCreatedAt(time()); $product->save(); $this->assertInstanceOf(Product::class, Product::getMapped($product)); }