Skip to content

Commit 1e1b087

Browse files
committed
feat: add Services::siteurifactory()
1 parent 68b85eb commit 1e1b087

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

system/Config/BaseService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use CodeIgniter\HTTP\Request;
3737
use CodeIgniter\HTTP\RequestInterface;
3838
use CodeIgniter\HTTP\ResponseInterface;
39+
use CodeIgniter\HTTP\SiteURIFactory;
3940
use CodeIgniter\HTTP\URI;
4041
use CodeIgniter\Images\Handlers\BaseHandler;
4142
use CodeIgniter\Language\Language;
@@ -121,6 +122,7 @@
121122
* @method static RouteCollection routes($getShared = true)
122123
* @method static Security security(App $config = null, $getShared = true)
123124
* @method static Session session(App $config = null, $getShared = true)
125+
* @method static SiteURIFactory siteurifactory(array $server = null, App $config = null, $getShared = true)
124126
* @method static Throttler throttler($getShared = true)
125127
* @method static Timer timer($getShared = true)
126128
* @method static Toolbar toolbar(ConfigToolbar $config = null, $getShared = true)

system/Config/Services.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,23 @@ public static function session(?App $config = null, bool $getShared = true)
682682
return $session;
683683
}
684684

685+
/**
686+
* The Factory for SiteURI.
687+
*
688+
* @return SiteURIFactory
689+
*/
690+
public static function siteurifactory(?array $server = null, ?App $config = null, bool $getShared = true)
691+
{
692+
if ($getShared) {
693+
return static::getSharedInstance('siteurifactory', $config);
694+
}
695+
696+
$config ??= config('App');
697+
$server ??= $_SERVER;
698+
699+
return new SiteURIFactory($server, $config);
700+
}
701+
685702
/**
686703
* The Throttler class provides a simple method for implementing
687704
* rate limiting in your applications.
@@ -743,7 +760,7 @@ public static function uri(?string $uri = null, bool $getShared = true)
743760

744761
if ($uri === null) {
745762
$appConfig = config(App::class);
746-
$factory = new SiteURIFactory($_SERVER, $appConfig);
763+
$factory = AppServices::siteurifactory($_SERVER, $appConfig);
747764

748765
return $factory->createFromGlobals();
749766
}

0 commit comments

Comments
 (0)