Skip to content

Commit 76dfd39

Browse files
committed
feat: add Services::siteurifactory()
1 parent 8464087 commit 76dfd39

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

system/Config/BaseService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use CodeIgniter\HTTP\Request;
3838
use CodeIgniter\HTTP\RequestInterface;
3939
use CodeIgniter\HTTP\ResponseInterface;
40+
use CodeIgniter\HTTP\SiteURIFactory;
4041
use CodeIgniter\HTTP\URI;
4142
use CodeIgniter\Images\Handlers\BaseHandler;
4243
use CodeIgniter\Language\Language;
@@ -47,6 +48,7 @@
4748
use CodeIgniter\Router\Router;
4849
use CodeIgniter\Security\Security;
4950
use CodeIgniter\Session\Session;
51+
use CodeIgniter\Superglobals;
5052
use CodeIgniter\Throttle\Throttler;
5153
use CodeIgniter\Typography\Typography;
5254
use CodeIgniter\Validation\ValidationInterface;
@@ -123,6 +125,7 @@
123125
* @method static RouteCollection routes($getShared = true)
124126
* @method static Security security(App $config = null, $getShared = true)
125127
* @method static Session session(App $config = null, $getShared = true)
128+
* @method static SiteURIFactory siteurifactory(App $config = null, Superglobals $superglobals = null, $getShared = true)
126129
* @method static Throttler throttler($getShared = true)
127130
* @method static Timer timer($getShared = true)
128131
* @method static Toolbar toolbar(ConfigToolbar $config = null, $getShared = true)

system/Config/Services.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,26 @@ public static function session(?SessionConfig $config = null, bool $getShared =
695695
return $session;
696696
}
697697

698+
/**
699+
* The Factory for SiteURI.
700+
*
701+
* @return SiteURIFactory
702+
*/
703+
public static function siteurifactory(
704+
?App $config = null,
705+
?Superglobals $superglobals = null,
706+
bool $getShared = true
707+
) {
708+
if ($getShared) {
709+
return static::getSharedInstance('siteurifactory', $config, $superglobals);
710+
}
711+
712+
$config ??= config('App');
713+
$superglobals ??= new Superglobals();
714+
715+
return new SiteURIFactory($config, $superglobals);
716+
}
717+
698718
/**
699719
* The Throttler class provides a simple method for implementing
700720
* rate limiting in your applications.
@@ -756,7 +776,7 @@ public static function uri(?string $uri = null, bool $getShared = true)
756776

757777
if ($uri === null) {
758778
$appConfig = config(App::class);
759-
$factory = new SiteURIFactory($appConfig, new Superglobals());
779+
$factory = AppServices::siteurifactory($appConfig, new Superglobals());
760780

761781
return $factory->createFromGlobals();
762782
}

0 commit comments

Comments
 (0)