10
10
use Jenssegers \Mongodb \Relations \EmbedsMany ;
11
11
use Jenssegers \Mongodb \Relations \EmbedsOne ;
12
12
use Jenssegers \Mongodb \Relations \EmbedsOneOrMany ;
13
- use MongoDate ;
14
- use MongoId ;
15
13
use ReflectionMethod ;
16
-
14
+ use MongoDB ;
17
15
abstract class Model extends BaseModel {
18
16
19
17
use HybridRelations;
@@ -54,8 +52,8 @@ public function getIdAttribute($value)
54
52
$ value = $ this ->attributes ['_id ' ];
55
53
}
56
54
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 )
59
57
{
60
58
return (string ) $ value ;
61
59
}
@@ -150,15 +148,15 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
150
148
}
151
149
152
150
/**
153
- * Convert a DateTime to a storable MongoDate object.
151
+ * Convert a DateTime to a storable MongoDB\BSON\UTCDateTime object.
154
152
*
155
153
* @param DateTime|int $value
156
- * @return MongoDate
154
+ * @return MongoDB\BSON\UTCDateTime
157
155
*/
158
156
public function fromDateTime ($ value )
159
157
{
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 )
162
160
{
163
161
return $ value ;
164
162
}
@@ -169,7 +167,8 @@ public function fromDateTime($value)
169
167
$ value = parent ::asDateTime ($ value );
170
168
}
171
169
172
- return new MongoDate ($ value ->getTimestamp ());
170
+
171
+ return new MongoDB \BSON \UTCDateTime ($ value ->getTimestamp ());
173
172
}
174
173
175
174
/**
@@ -180,8 +179,8 @@ public function fromDateTime($value)
180
179
*/
181
180
protected function asDateTime ($ value )
182
181
{
183
- // Convert MongoDate instances.
184
- if ($ value instanceof MongoDate )
182
+ // Convert MongoDB\BSON\UTCDateTime instances.
183
+ if ($ value instanceof MongoDB \ BSON \UTCDateTime )
185
184
{
186
185
return Carbon::createFromTimestamp ($ value ->sec );
187
186
}
@@ -202,11 +201,11 @@ protected function getDateFormat()
202
201
/**
203
202
* Get a fresh timestamp for the model.
204
203
*
205
- * @return MongoDate
204
+ * @return MongoDB\BSON\UTCDateTime
206
205
*/
207
206
public function freshTimestamp ()
208
- {
209
- return new MongoDate ;
207
+ {
208
+ return round ( microtime ( true ) * 1000 ) ;
210
209
}
211
210
212
211
/**
@@ -298,7 +297,7 @@ protected function getAttributeFromArray($key)
298
297
*/
299
298
public function setAttribute ($ key , $ value )
300
299
{
301
- // Convert _id to MongoId .
300
+ // Convert _id to MongoDB\BSON\ObjectID .
302
301
if ($ key == '_id ' and is_string ($ value ))
303
302
{
304
303
$ builder = $ this ->newBaseQueryBuilder ();
@@ -337,7 +336,7 @@ public function attributesToArray()
337
336
// nicely when your models are converted to JSON.
338
337
foreach ($ attributes as $ key => &$ value )
339
338
{
340
- if ($ value instanceof MongoId )
339
+ if ($ value instanceof MongoDB \ BSON \ObjectID )
341
340
{
342
341
$ value = (string ) $ value ;
343
342
}
@@ -355,29 +354,6 @@ public function attributesToArray()
355
354
return $ attributes ;
356
355
}
357
356
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
-
381
357
/**
382
358
* Remove one or more fields.
383
359
*
0 commit comments