createDBRef() public method

Creates a database reference
public createDBRef ( array | object $document_or_id ) : array
$document_or_id array | object Object to which to create a reference.
return array Returns a database reference array.
Beispiel #1
0
 /**
  * Do any data prep tasks, such as converting Links to DBRefs.
  *
  * @param array $data
  *   The array of data.
  */
 protected function prepareWriteData(array &$data)
 {
     foreach ($data as $key => $value) {
         if (is_object($value) && $value instanceof Link) {
             $data[$key] = $this->collection->createDBRef($value->getTarget());
         }
     }
 }
 public function testCreateDBRef()
 {
     $ref = $this->object->createDBRef(array('foo' => 'bar'));
     $this->assertEquals($ref, null);
     $arr = array('_id' => new MongoId());
     $ref = $this->object->createDBRef($arr);
     $this->assertNotNull($ref);
     $this->assertTrue(is_array($ref));
     $arr = array('_id' => 1);
     $ref = $this->object->createDBRef($arr);
     $this->assertNotNull($ref);
     $this->assertTrue(is_array($ref));
     $ref = $this->object->createDBRef(new MongoId());
     $this->assertNotNull($ref);
     $this->assertTrue(is_array($ref));
 }
 /**
  * Sets the metadata array on the thread.
  *
  * By default, Mongo will not include "$db" when creating the participant
  * reference. We'll add that manually to be consistent with Doctrine.
  *
  * @param array &$thread
  */
 private function createThreadMetadata(array &$thread)
 {
     $metadata = array();
     $participantIds = array_keys($thread['datesOfLastMessageWrittenByOtherParticipant'] + $thread['datesOfLastMessageWrittenByParticipant'] + $thread['isDeletedByParticipant']);
     foreach ($participantIds as $participantId) {
         $meta = array('isDeleted' => false, 'participant' => $this->participantCollection->createDBRef(array('_id' => new \MongoId($participantId))) + array('$db' => (string) $this->participantCollection->db));
         if (isset($thread['isDeletedByParticipant'][$participantId])) {
             $meta['isDeleted'] = $thread['isDeletedByParticipant'][$participantId];
         }
         if (isset($thread['datesOfLastMessageWrittenByOtherParticipant'][$participantId])) {
             $meta['lastMessageDate'] = new \MongoDate($thread['datesOfLastMessageWrittenByOtherParticipant'][$participantId]);
         }
         if (isset($thread['datesOfLastMessageWrittenByParticipant'][$participantId])) {
             $meta['lastParticipantMessageDate'] = new \MongoDate($thread['datesOfLastMessageWrittenByParticipant'][$participantId]);
         }
         $metadata[] = $meta;
     }
     $thread['metadata'] = $metadata;
 }
Beispiel #4
0
 /**
  * Wrapper method for MongoCollection::createDBRef().
  *
  * @see http://php.net/manual/en/mongocollection.createdbref.php
  * @param mixed $documentOrId
  * @return array
  */
 public function createDBRef($documentOrId)
 {
     return $this->mongoCollection->createDBRef($documentOrId);
 }
Beispiel #5
0
 protected function doCreateDBRef(array $a)
 {
     return $this->mongoCollection->createDBRef($a);
 }