Skip to content

Commit

Permalink
feat: add param $scheme to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 17, 2023
1 parent 7a01845 commit cbd07ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions system/HTTP/SiteURI.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ class SiteURI extends URI
/**
* @param string $relativePath URI path relative to baseURL. May include
* queries or fragments.
* @param string $host Hostname. If it is not in $allowedHostnames,
* @param string $host Optional hostname. If it is not in $allowedHostnames,
* just be ignored.
* @param string $scheme Optional scheme. 'http' or 'https'.
* @phpstan-param 'http'|'https'|'' $scheme
*/
public function __construct(App $configApp, string $relativePath = '', string $host = '')
public function __construct(App $configApp, string $relativePath = '', string $host = '', string $scheme = '')
{
$this->baseURL = $this->normalizeBaseURL($configApp);
$this->indexPage = $configApp->indexPage;
Expand All @@ -100,7 +102,9 @@ public function __construct(App $configApp, string $relativePath = '', string $h
$uri = new URI($tempUri);

// Update scheme
if ($configApp->forceGlobalSecureRequests) {
if ($scheme !== '') {
$uri->setScheme($scheme);
} elseif ($configApp->forceGlobalSecureRequests) {
$uri->setScheme('https');
}

Expand Down
10 changes: 10 additions & 0 deletions tests/system/HTTP/SiteURITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function testConstructorHost()
$this->assertSame('/index.php/', $uri->getPath());
}

public function testConstructorScheme()
{
$config = new App();

$uri = new SiteURI($config, '', '', 'https');

$this->assertInstanceOf(SiteURI::class, $uri);
$this->assertSame('https://example.com/index.php/', (string) $uri);
}

public function testConstructorSubfolder()
{
$config = new App();
Expand Down

0 comments on commit cbd07ac

Please sign in to comment.