yii\mongodb\QueryBuilder::ensureMongoId PHP Method

ensureMongoId() protected method

If array given, each element of it will be processed.
protected ensureMongoId ( mixed $rawId ) : array | MongoDB\BSON\ObjectID
$rawId mixed raw id(s).
return array | MongoDB\BSON\ObjectID normalized id(s).
    protected function ensureMongoId($rawId)
    {
        if (is_array($rawId)) {
            $result = [];
            foreach ($rawId as $key => $value) {
                $result[$key] = $this->ensureMongoId($value);
            }
            return $result;
        } elseif (is_object($rawId)) {
            if ($rawId instanceof ObjectID) {
                return $rawId;
            } else {
                $rawId = (string) $rawId;
            }
        }
        try {
            $mongoId = new ObjectID($rawId);
        } catch (InvalidArgumentException $e) {
            // invalid id format
            $mongoId = $rawId;
        }
        return $mongoId;
    }