Skip to content

Commit 7be6b59

Browse files
authored
Merge pull request #1302 from hydephp/check-for-config-flags-in-server-globals-when-loading-the-configuration
Check for config flags in server globals when loading the configuration
2 parents bf6fe27 + 44cb816 commit 7be6b59

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This serves two purposes:
2222
- for now removed features.
2323

2424
### Fixed
25-
- for any bug fixes.
25+
- Fixed https://github.com/hydephp/develop/issues/1301 in https://github.com/hydephp/develop/pull/1302
2626

2727
### Security
2828
- in case of vulnerabilities.

packages/framework/src/Foundation/Internal/LoadConfiguration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
3434
parent::loadConfigurationFiles($app, $repository);
3535

3636
$this->mergeConfigurationFiles($repository);
37+
38+
$this->loadRuntimeConfiguration($app, $repository);
3739
}
3840

3941
private function mergeConfigurationFiles(RepositoryContract $repository): void
@@ -73,4 +75,14 @@ private static function providePharSupportIfNeeded(array &$files): void
7375
$files['app'] = dirname(__DIR__, 6).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
7476
}
7577
}
78+
79+
private function loadRuntimeConfiguration(Application $app, RepositoryContract $repository)
80+
{
81+
if ($app->runningInConsole() && isset($_SERVER['argv'])) {
82+
// Check if the `--pretty-urls` CLI argument is set, and if so, set the config value accordingly.
83+
if (in_array('--pretty-urls', $_SERVER['argv'], true)) {
84+
$repository->set('hyde.pretty_urls', true);
85+
}
86+
}
87+
}
7688
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Framework\Testing\Unit;
6+
7+
use Hyde\Foundation\Application;
8+
use Hyde\Foundation\Internal\LoadConfiguration;
9+
use Hyde\Testing\UnitTestCase;
10+
11+
/**
12+
* @covers \Hyde\Foundation\Internal\LoadConfiguration
13+
*/
14+
class LoadConfigurationTest extends UnitTestCase
15+
{
16+
public function testItLoadsRuntimeConfiguration()
17+
{
18+
$serverBackup = $_SERVER;
19+
20+
$_SERVER['argv'] = ['--pretty-urls'];
21+
22+
$app = new Application(getcwd());
23+
24+
$loader = new LoadConfiguration();
25+
$loader->bootstrap($app);
26+
27+
$this->assertTrue(config('hyde.pretty_urls'));
28+
29+
$_SERVER = $serverBackup;
30+
31+
$loader->bootstrap($app);
32+
$this->assertFalse(config('hyde.pretty_urls'));
33+
}
34+
}

0 commit comments

Comments
 (0)