/** @override */
 public function findOne(array $query = array(), array $fields = array())
 {
     if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) {
         $discriminatorValues = $this->getClassDiscriminatorValues($this->class);
         $query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues);
     }
     $query = $this->prepareQuery($query);
     if ($this->eventManager->hasListeners(CollectionEvents::preFindOne)) {
         $this->eventManager->dispatchEvent(CollectionEvents::preFindOne, new CollectionEventArgs($this, $query));
     }
     if ($this->loggerCallable) {
         $this->log(array('findOne' => true, 'query' => $query, 'fields' => $fields));
     }
     if ($this->mongoCollection instanceof \MongoGridFS) {
         $file = $this->mongoCollection->findOne($query);
         $data = $file->file;
         $data[$this->class->file] = $file;
         return $data;
     }
     $result = $this->mongoCollection->findOne($query, $fields);
     if ($this->eventManager->hasListeners(CollectionEvents::postFindOne)) {
         $this->eventManager->dispatchEvent(CollectionEvents::postFindOne, new CollectionEventArgs($this, $result));
     }
     return $result;
 }
Example #2
0
 /** @override */
 public function findOne(array $query = array(), array $fields = array())
 {
     if ($this->_eventManager->hasListeners(CollectionEvents::preFindOne)) {
         $this->_eventManager->dispatchEvent(CollectionEvents::preFindOne, new CollectionEventArgs($this, $query));
     }
     if ($this->_loggerCallable) {
         $this->log(array('findOne' => true, 'query' => $query, 'fields' => $fields));
     }
     if ($this->_mongoCollection instanceof \MongoGridFS) {
         $file = $this->_mongoCollection->findOne($query);
         $data = $file->file;
         $data[$this->_class->file] = $file;
         return $data;
     }
     $result = $this->_mongoCollection->findOne($query, $fields);
     if ($this->_eventManager->hasListeners(CollectionEvents::postFindOne)) {
         $this->_eventManager->dispatchEvent(CollectionEvents::postFindOne, new CollectionEventArgs($this, $result));
     }
     return $result;
 }