public function testEnsureMongoId() { $mongoId1 = new MongoId(); $mongoId2 = new MongoId(); $this->assertEquals($mongoId1, $mongoId1); $this->assertEquals($mongoId1, Collection::ensureMongoId((string) $mongoId1)); $this->assertEquals([$mongoId1, $mongoId2], Collection::ensureMongoId([(string) $mongoId1, (string) $mongoId2])); }
/** * @param mixed $query * @param string $pk * @return array */ public static function normalize($query = null, $pk = '_id') { if ($query === null) { $query = []; } else { if ($query instanceof Criteria) { $query = $query->asArray(); $query = $query['$query']; } } if (is_scalar($query) || $query instanceof \MongoId) { $query = Collection::isValidMongoId($query) ? Collection::ensureMongoId($query) : $query; $query = [$pk => $query]; } else { if (!empty($query[$pk])) { $query[$pk] = Collection::isValidMongoId($query[$pk]) ? Collection::ensureMongoId($query[$pk]) : $query[$pk]; } else { if (empty($query)) { $query = []; } } } return $query; }
/** * @param array|string $id * @return array|MongoId */ public static function ensureMongoId($id) { return Collection::ensureMongoId($id); }