function it_aggregate_attributes_to_export($dm, Collection $collection, Cursor $cursor) { $dm->getDocumentCollection('foobar')->willReturn($collection); $cursor->toArray()->willReturn([['_id' => 'fooz'], ['_id' => 'baz']]); $collection->aggregate([['$match' => ['_id' => ['$in' => [new \MongoId('55db20922a114eb9078b5130')]]]], ['$unwind' => '$values'], ['$group' => ['_id' => '$values.attribute']]])->willReturn($cursor); $this->getAvailableAttributeIdsToExport(['55db20922a114eb9078b5130'])->shouldReturn(['fooz', 'baz']); }
function it_counts_complete_products_per_channels(Cursor $cursor) { $countList = array(0, 1, 2); $cursor->count()->will(function () use(&$countList) { return array_shift($countList); }); $this->getCompleteProductsCountPerChannels()->shouldReturn(array(array('locale' => 'en_US', 'label' => 'ECommerce', 'total' => 0), array('locale' => 'fr_FR', 'label' => 'ECommerce', 'total' => 1), array('locale' => 'en_US', 'label' => 'Mobile', 'total' => 2))); }
/** @override */ public function current() { $current = parent::current(); if ($current && $this->hydrate) { return $this->unitOfWork->getOrCreateDocument($this->class->name, $current, $this->hints); } return $current ? $current : null; }
private function applyOptionsToCursor(Cursor $cursor, QueryOptions $options) { if ($this->timeLimit !== null) { $cursor->timeout($this->timeLimit); } return $cursor->skip($options->getOffset())->limit($options->getLimit()); }
/** * Prepare the Cursor returned by {@link Query::execute()}. * * This method will apply cursor options present in the query structure * array. The Cursor may also be wrapped with an EagerCursor. * * @param Cursor $cursor * @return CursorInterface */ protected function prepareCursor(Cursor $cursor) { /* Note: if this cursor resulted from a mapReduce command, applying the * read preference may be undesirable. Results would have been written * to the primary and replication may still be in progress. */ if (isset($this->query['readPreference'])) { $cursor->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']); } foreach ($this->getQueryOptions('hint', 'immortal', 'limit', 'skip', 'slaveOkay', 'sort', 'maxTimeMS') as $key => $value) { $cursor->{$key}($value); } if (!empty($this->query['snapshot'])) { $cursor->snapshot(); } if (!empty($this->query['eagerCursor'])) { $cursor = new EagerCursor($cursor); } if (isset($this->query['useIdentifierKeys'])) { $cursor->setUseIdentifierKeys($this->query['useIdentifierKeys']); } return $cursor; }
/** * Wraps the supplied base cursor as an ODM one. * * @param Doctrine\MongoDB\Cursor $cursor The base cursor * * @return Cursor An ODM cursor */ private function wrapCursor(BaseCursor $cursor) { if ($cursor instanceof BaseLoggableCursor) { return new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $cursor->getLoggerCallable()); } else { return new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery()); } }
/** * Wraps the supplied base cursor as an ODM one. * * @param Doctrine\MongoDB\Cursor $cursor The base cursor * * @return Cursor An ODM cursor */ private function wrapCursor(BaseCursor $cursor) { $mongoCursor = $cursor->getMongoCursor(); if ($cursor instanceof BaseLoggableCursor) { return new LoggableCursor( $mongoCursor, $this->uow, $this->class, $cursor->getLoggerCallable(), $cursor->getQuery(), $cursor->getFields() ); } else { return new Cursor($mongoCursor, $this->uow, $this->class); } }
protected function prepareCursor(Cursor $cursor) { $cursor->limit($this->query['limit']); $cursor->skip($this->query['skip']); $cursor->sort($this->query['sort']); $cursor->immortal($this->query['immortal']); if (null !== $this->query['slaveOkay']) { $cursor->slaveOkay($this->query['slaveOkay']); } if ($this->query['snapshot']) { $cursor->snapshot(); } foreach ($this->query['hints'] as $keyPattern) { $cursor->hint($keyPattern); } if ($this->query['eagerCursor'] === true) { $cursor = new EagerCursor($cursor); } return $cursor; }
private function wrapCursor(BaseCursor $baseCursor, array $hints) { if ($baseCursor instanceof BaseLoggableCursor) { $cursor = new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $baseCursor->getLoggerCallable()); } else { $cursor = new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery()); } $cursor->hydrate($this->hydrate); $cursor->setHints($hints); return $cursor; }
/** * Wrapper method for MongoCursor::timeout(). * * @see \Doctrine\MongoDB\Cursor::timeout() * @see http://php.net/manual/en/mongocursor.timeout.php * @param integer $ms * @return self */ public function timeout($ms) { $this->baseCursor->timeout($ms); return $this; }
protected function prepareCursor(Cursor $cursor) { $cursor->limit($this->query['limit']); $cursor->skip($this->query['skip']); $cursor->sort($this->query['sort']); $cursor->immortal($this->query['immortal']); $cursor->slaveOkay($this->query['slaveOkay']); if ($this->query['snapshot']) { $cursor->snapshot(); } foreach ($this->query['hints'] as $keyPattern) { $cursor->hint($keyPattern); } }
private function wrapCursor(BaseCursor $baseCursor) { $mongoCursor = $baseCursor->getMongoCursor(); if ($baseCursor instanceof BaseLoggableCursor) { $cursor = new LoggableCursor($mongoCursor, $this->dm->getUnitOfWork(), $this->class, $baseCursor->getLoggerCallable(), $baseCursor->getQuery(), $baseCursor->getFields()); } else { $cursor = new Cursor($mongoCursor, $this->dm->getUnitOfWork(), $this->class); } $cursor->hydrate($this->hydrate); $cursor->refresh($this->refresh); return $cursor; }
/** @override */ public function sort($fields) { $fields = $this->unitOfWork->getDocumentPersister($this->class->name)->prepareSort($fields); $fields = parent::sort($fields); return $this; }
/** @override */ public function getNext() { $next = parent::getNext(); if ($next && $this->hydrate) { return $this->unitOfWork->getOrCreateDocument($this->class->name, $next, $this->hints); } return $next ? $next : null; }