Skip to content

Commit cbd07ac

Browse files
committed
feat: add param $scheme to constructor
1 parent 7a01845 commit cbd07ac

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

system/HTTP/SiteURI.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class SiteURI extends URI
7373
/**
7474
* @param string $relativePath URI path relative to baseURL. May include
7575
* queries or fragments.
76-
* @param string $host Hostname. If it is not in $allowedHostnames,
76+
* @param string $host Optional hostname. If it is not in $allowedHostnames,
7777
* just be ignored.
78+
* @param string $scheme Optional scheme. 'http' or 'https'.
79+
* @phpstan-param 'http'|'https'|'' $scheme
7880
*/
79-
public function __construct(App $configApp, string $relativePath = '', string $host = '')
81+
public function __construct(App $configApp, string $relativePath = '', string $host = '', string $scheme = '')
8082
{
8183
$this->baseURL = $this->normalizeBaseURL($configApp);
8284
$this->indexPage = $configApp->indexPage;
@@ -100,7 +102,9 @@ public function __construct(App $configApp, string $relativePath = '', string $h
100102
$uri = new URI($tempUri);
101103

102104
// Update scheme
103-
if ($configApp->forceGlobalSecureRequests) {
105+
if ($scheme !== '') {
106+
$uri->setScheme($scheme);
107+
} elseif ($configApp->forceGlobalSecureRequests) {
104108
$uri->setScheme('https');
105109
}
106110

tests/system/HTTP/SiteURITest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public function testConstructorHost()
7070
$this->assertSame('/index.php/', $uri->getPath());
7171
}
7272

73+
public function testConstructorScheme()
74+
{
75+
$config = new App();
76+
77+
$uri = new SiteURI($config, '', '', 'https');
78+
79+
$this->assertInstanceOf(SiteURI::class, $uri);
80+
$this->assertSame('https://example.com/index.php/', (string) $uri);
81+
}
82+
7383
public function testConstructorSubfolder()
7484
{
7585
$config = new App();

0 commit comments

Comments
 (0)