/** * @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 string|MongoId $id * @return bool */ public static function isValidMongoId($id) { return Collection::isValidMongoId($id); }