/** * 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; }
/** * 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); }
protected function doCreateDBRef(array $a) { return $this->mongoCollection->createDBRef($a); }