File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of the Phalcon Framework.
5+ *
6+ * (c) Phalcon Team <[email protected] > 7+ *
8+ * For the full copyright and license information, please view the LICENSE.txt
9+ * file that was distributed with this source code.
10+ */
11+
12+ declare (strict_types=1 );
13+
14+ namespace Phalcon \Incubator \MongoDB \Helper ;
15+
16+ use DateTimeInterface ;
17+ use MongoDB \BSON \ObjectID ;
18+ use MongoDB \BSON \UTCDateTime ;
19+
20+ /**
21+ * Class Mongo
22+ *
23+ * @package Phalcon\Incubator\MongoDB\Helper
24+ */
25+ class Mongo
26+ {
27+ /**
28+ * Check if id parameter is a valid ObjectID
29+ *
30+ * @param mixed $id
31+ * @return bool
32+ * @noinspection MissingParameterTypeDeclarationInspection
33+ */
34+ final public static function isValidObjectId ($ id ): bool
35+ {
36+ return $ id instanceof ObjectID || preg_match ('/^[a-f\d]{24}$/i ' , $ id );
37+ }
38+
39+ /**
40+ * Convert a DateTime object to UTCDateTime from MongoDB
41+ *
42+ * @param DateTimeInterface $dateTime
43+ * @return UTCDateTime
44+ */
45+ final public static function convertDatetime (DateTimeInterface $ dateTime ): UTCDateTime
46+ {
47+ return new UTCDateTime ($ dateTime ->getTimestamp () * 1000 );
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments