1010use Jenssegers \Mongodb \Relations \EmbedsMany ;
1111use Jenssegers \Mongodb \Relations \EmbedsOne ;
1212use Jenssegers \Mongodb \Relations \EmbedsOneOrMany ;
13- use MongoDate ;
14- use MongoId ;
1513use ReflectionMethod ;
16-
14+ use MongoDB ;
1715abstract class Model extends BaseModel {
1816
1917 use HybridRelations;
@@ -54,8 +52,8 @@ public function getIdAttribute($value)
5452 $ value = $ this ->attributes ['_id ' ];
5553 }
5654
57- // Convert MongoId 's to string.
58- if ($ value instanceof MongoId )
55+ // Convert MongoDB\BSON\ObjectID 's to string.
56+ if ($ value instanceof MongoDB \ BSON \ObjectID )
5957 {
6058 return (string ) $ value ;
6159 }
@@ -150,15 +148,15 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
150148 }
151149
152150 /**
153- * Convert a DateTime to a storable MongoDate object.
151+ * Convert a DateTime to a storable MongoDB\BSON\UTCDateTime object.
154152 *
155153 * @param DateTime|int $value
156- * @return MongoDate
154+ * @return MongoDB\BSON\UTCDateTime
157155 */
158156 public function fromDateTime ($ value )
159157 {
160- // If the value is already a MongoDate instance, we don't need to parse it.
161- if ($ value instanceof MongoDate )
158+ // If the value is already a MongoDB\BSON\UTCDateTime instance, we don't need to parse it.
159+ if ($ value instanceof MongoDB \ BSON \UTCDateTime )
162160 {
163161 return $ value ;
164162 }
@@ -169,7 +167,8 @@ public function fromDateTime($value)
169167 $ value = parent ::asDateTime ($ value );
170168 }
171169
172- return new MongoDate ($ value ->getTimestamp ());
170+
171+ return new MongoDB \BSON \UTCDateTime ($ value ->getTimestamp ());
173172 }
174173
175174 /**
@@ -180,8 +179,8 @@ public function fromDateTime($value)
180179 */
181180 protected function asDateTime ($ value )
182181 {
183- // Convert MongoDate instances.
184- if ($ value instanceof MongoDate )
182+ // Convert MongoDB\BSON\UTCDateTime instances.
183+ if ($ value instanceof MongoDB \ BSON \UTCDateTime )
185184 {
186185 return Carbon::createFromTimestamp ($ value ->sec );
187186 }
@@ -202,11 +201,11 @@ protected function getDateFormat()
202201 /**
203202 * Get a fresh timestamp for the model.
204203 *
205- * @return MongoDate
204+ * @return MongoDB\BSON\UTCDateTime
206205 */
207206 public function freshTimestamp ()
208- {
209- return new MongoDate ;
207+ {
208+ return round ( microtime ( true ) * 1000 ) ;
210209 }
211210
212211 /**
@@ -298,7 +297,7 @@ protected function getAttributeFromArray($key)
298297 */
299298 public function setAttribute ($ key , $ value )
300299 {
301- // Convert _id to MongoId .
300+ // Convert _id to MongoDB\BSON\ObjectID .
302301 if ($ key == '_id ' and is_string ($ value ))
303302 {
304303 $ builder = $ this ->newBaseQueryBuilder ();
@@ -337,7 +336,7 @@ public function attributesToArray()
337336 // nicely when your models are converted to JSON.
338337 foreach ($ attributes as $ key => &$ value )
339338 {
340- if ($ value instanceof MongoId )
339+ if ($ value instanceof MongoDB \ BSON \ObjectID )
341340 {
342341 $ value = (string ) $ value ;
343342 }
@@ -355,29 +354,6 @@ public function attributesToArray()
355354 return $ attributes ;
356355 }
357356
358- /**
359- * Determine if the new and old values for a given key are numerically equivalent.
360- *
361- * @param string $key
362- * @return bool
363- */
364- protected function originalIsNumericallyEquivalent ($ key )
365- {
366- $ current = $ this ->attributes [$ key ];
367-
368- $ original = $ this ->original [$ key ];
369-
370- // Date comparison.
371- if (in_array ($ key , $ this ->getDates ()))
372- {
373- $ current = $ current instanceof MongoDate ? $ this ->asDateTime ($ current ) : $ current ;
374- $ original = $ original instanceof MongoDate ? $ this ->asDateTime ($ original ) : $ original ;
375- return $ current == $ original ;
376- }
377-
378- return parent ::originalIsNumericallyEquivalent ($ key );
379- }
380-
381357 /**
382358 * Remove one or more fields.
383359 *
0 commit comments