public function testEncodeDecodeUniversalTimestamp_HistoricalDate_Same() { $model = new TestMongoDateModel(); $model->universalTimestamp = UniversalTimestamp::fromStringTimestamp('2001-01-01 12:01:01.321'); $encoded = MongoEncoder::encode($model); $this->assertInstanceOf(UTCDateTime::class, $encoded['universalTimestamp']); // var_dump($encoded); $decodedModel = new TestMongoDateModel(); MongoDecoder::decode($decodedModel, $encoded); $this->assertEquals($model->universalTimestamp, $decodedModel->universalTimestamp); // $iso8601 = $decodedModel->universalTimestamp->asFormattedString(UniversalTimestamp::ISO8601_WITH_MILLISECONDS); // var_dump($iso8601); }
public function readSubDocument($model, $rootId, $property, $id) { CodeGuard::checkTypeAndThrow($rootId, 'string'); CodeGuard::checkTypeAndThrow($id, 'string'); $data = $this->_collection->findOne(array("_id" => self::mongoID($rootId)), array('projection' => $property . '.' . $id)); if ($data === NULL) { throw new \Exception("Could not find {$property}={$id} in {$rootId}"); } // TODO Check this out on nested sub docs > 1 $data = $data[$property][$id]; MongoDecoder::decode($model, $data, $id); }
/** * Sets the public properties of $model to values from $values[propertyName] * @param object $model * @param array $values A mixed array of JSON (like) data. * @param string $id */ public static function decode($model, $values, $id = '') { $decoder = new MongoDecoder(); $decoder->_decode($model, $values, $id); }