diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index 98cb19fde9e7..7dc736088ccd 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -36,6 +36,7 @@ use CodeIgniter\HTTP\Request; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\SiteURIFactory; use CodeIgniter\HTTP\URI; use CodeIgniter\Images\Handlers\BaseHandler; use CodeIgniter\Language\Language; @@ -121,6 +122,7 @@ * @method static RouteCollection routes($getShared = true) * @method static Security security(App $config = null, $getShared = true) * @method static Session session(App $config = null, $getShared = true) + * @method static SiteURIFactory siteurifactory(array $server = null, App $config = null, $getShared = true) * @method static Throttler throttler($getShared = true) * @method static Timer timer($getShared = true) * @method static Toolbar toolbar(ConfigToolbar $config = null, $getShared = true) diff --git a/system/Config/Services.php b/system/Config/Services.php index cc923ab14f83..3a5ac94c6c42 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -682,6 +682,23 @@ public static function session(?App $config = null, bool $getShared = true) return $session; } + /** + * The Factory for SiteURI. + * + * @return SiteURIFactory + */ + public static function siteurifactory(?array $server = null, ?App $config = null, bool $getShared = true) + { + if ($getShared) { + return static::getSharedInstance('siteurifactory', $config); + } + + $config ??= config('App'); + $server ??= $_SERVER; + + return new SiteURIFactory($server, $config); + } + /** * The Throttler class provides a simple method for implementing * rate limiting in your applications. @@ -743,7 +760,7 @@ public static function uri(?string $uri = null, bool $getShared = true) if ($uri === null) { $appConfig = config(App::class); - $factory = new SiteURIFactory($_SERVER, $appConfig); + $factory = AppServices::siteurifactory($_SERVER, $appConfig); return $factory->createFromGlobals(); }