Skip to content

Commit 8265dc2

Browse files
authored
Merge pull request #5962 from kenjis/remove-SERVER-from-route
refactor: remove `$_SERVER['HTTP_HOST']` in RouteCollection
2 parents dcd6b97 + fe627b3 commit 8265dc2

24 files changed

+140
-38
lines changed

system/Router/RouteCollection.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,20 @@ class RouteCollection implements RouteCollectionInterface
218218
*/
219219
protected $prioritizeDetected = false;
220220

221+
/**
222+
* The current hostname from $_SERVER['HTTP_HOST']
223+
*/
224+
private ?string $httpHost = null;
225+
221226
/**
222227
* Constructor
223228
*/
224229
public function __construct(FileLocator $locator, Modules $moduleConfig)
225230
{
226231
$this->fileLocator = $locator;
227232
$this->moduleConfig = $moduleConfig;
233+
234+
$this->httpHost = Services::request()->getServer('HTTP_HOST');
228235
}
229236

230237
/**
@@ -1176,7 +1183,7 @@ protected function create(string $verb, string $from, $to, ?array $options = nul
11761183
// Hostname limiting?
11771184
if (! empty($options['hostname'])) {
11781185
// @todo determine if there's a way to whitelist hosts?
1179-
if (isset($_SERVER['HTTP_HOST']) && strtolower($_SERVER['HTTP_HOST']) !== strtolower($options['hostname'])) {
1186+
if (isset($this->httpHost) && strtolower($this->httpHost) !== strtolower($options['hostname'])) {
11801187
return;
11811188
}
11821189

@@ -1302,7 +1309,7 @@ private function getMethodParams(string $from): string
13021309
private function checkSubdomains($subdomains): bool
13031310
{
13041311
// CLI calls can't be on subdomain.
1305-
if (! isset($_SERVER['HTTP_HOST'])) {
1312+
if (! isset($this->httpHost)) {
13061313
return false;
13071314
}
13081315

@@ -1337,7 +1344,7 @@ private function determineCurrentSubdomain()
13371344
// We have to ensure that a scheme exists
13381345
// on the URL else parse_url will mis-interpret
13391346
// 'host' as the 'path'.
1340-
$url = $_SERVER['HTTP_HOST'];
1347+
$url = $this->httpHost;
13411348
if (strpos($url, 'http') !== 0) {
13421349
$url = 'http://' . $url;
13431350
}

tests/system/Commands/GenerateKeyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
/**
1818
* @internal
19+
*
20+
* @group SeparateProcess
1921
*/
2022
final class GenerateKeyTest extends CIUnitTestCase
2123
{

tests/system/CommonFunctionsSendTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @internal
18+
*
19+
* @group SeparateProcess
1820
*/
1921
final class CommonFunctionsSendTest extends CIUnitTestCase
2022
{

tests/system/CommonFunctionsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* @backupGlobals enabled
3838
*
3939
* @internal
40+
*
41+
* @group SeparateProcess
4042
*/
4143
final class CommonFunctionsTest extends CIUnitTestCase
4244
{

tests/system/Config/BaseConfigTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
/**
2323
* @internal
24+
*
25+
* @group SeparateProcess
2426
*/
2527
final class BaseConfigTest extends CIUnitTestCase
2628
{

tests/system/Config/ConfigTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* @internal
20+
*
21+
* @group SeparateProcess
2022
*/
2123
final class ConfigTest extends CIUnitTestCase
2224
{

tests/system/Config/DotEnvTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @backupGlobals enabled
1919
*
2020
* @internal
21+
*
22+
* @group SeparateProcess
2123
*/
2224
final class DotEnvTest extends CIUnitTestCase
2325
{

tests/system/Config/ServicesTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
/**
5050
* @internal
51+
*
52+
* @group SeparateProcess
5153
*/
5254
final class ServicesTest extends CIUnitTestCase
5355
{

tests/system/Events/EventsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* @internal
20+
*
21+
* @group SeparateProcess
2022
*/
2123
final class EventsTest extends CIUnitTestCase
2224
{

tests/system/Filters/HoneypotTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @backupGlobals enabled
2121
*
2222
* @internal
23+
*
24+
* @group SeparateProcess
2325
*/
2426
final class HoneypotTest extends CIUnitTestCase
2527
{

0 commit comments

Comments
 (0)