public function bsonUnserialize(array $data) { $this->_saved = $data; $this->_data = $data; $this->_conn = \mongo\Connection::lastConnection(); $this->_ns = \mongo\Connection::lastQuery()['namespace']; array_walk_recursive($this->_data, function (&$item, $key) { if ($item instanceof \MongoDB\BSON\UTCDateTime) { $item = \mongo\type\DateTime::fromBSON($item); } elseif ($item instanceof \MongoDB\BSON\Timestamp) { $item = \mongo\type\Timestamp::fromBSON($item); } }); }
public static function bsonSerialize($item, $tag, $flags) { if ($tag === 'DateTime') { return \mongo\type\DateTime::fromString($item); } elseif ($tag === 'Timestamp') { return \mongo\type\Timestamp::fromString($item); } elseif ($tag === 'ObjectID') { return new \MongoDB\BSON\ObjectID($item); } elseif ($tag === 'Binary') { return \mongo\type\Binary::bsonImport($item); } elseif ($tag === 'Javascript') { return \mongo\type\Javascript::bsonImport($item); } elseif ($tag === 'Regex') { return \mongo\type\Regex::bsonImport($item); } elseif ($tag === 'MaxKey') { return new \MongoDB\BSON\MaxKey(); } elseif ($tag === 'MinKey') { return new \MongoDB\BSON\MinKey(); } }