Skip to content

Commit

Permalink
feat: add Services::siteurifactory()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 24, 2023
1 parent 68b85eb commit 1e1b087
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 1e1b087

Please sign in to comment.