Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for config flags in server globals when loading the configuration #1302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This serves two purposes:
- for now removed features.

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

### Security
- in case of vulnerabilities.
12 changes: 12 additions & 0 deletions packages/framework/src/Foundation/Internal/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
parent::loadConfigurationFiles($app, $repository);

$this->mergeConfigurationFiles($repository);

$this->loadRuntimeConfiguration($app, $repository);
}

private function mergeConfigurationFiles(RepositoryContract $repository): void
Expand Down Expand Up @@ -73,4 +75,14 @@ private static function providePharSupportIfNeeded(array &$files): void
$files['app'] = dirname(__DIR__, 6).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
}
}

private function loadRuntimeConfiguration(Application $app, RepositoryContract $repository)
{
if ($app->runningInConsole() && isset($_SERVER['argv'])) {
// Check if the `--pretty-urls` CLI argument is set, and if so, set the config value accordingly.
if (in_array('--pretty-urls', $_SERVER['argv'], true)) {
$repository->set('hyde.pretty_urls', true);
}
}
}
}
34 changes: 34 additions & 0 deletions packages/framework/tests/Unit/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit;

use Hyde\Foundation\Application;
use Hyde\Foundation\Internal\LoadConfiguration;
use Hyde\Testing\UnitTestCase;

/**
* @covers \Hyde\Foundation\Internal\LoadConfiguration
*/
class LoadConfigurationTest extends UnitTestCase
{
public function testItLoadsRuntimeConfiguration()
{
$serverBackup = $_SERVER;

$_SERVER['argv'] = ['--pretty-urls'];

$app = new Application(getcwd());

$loader = new LoadConfiguration();
$loader->bootstrap($app);

$this->assertTrue(config('hyde.pretty_urls'));

$_SERVER = $serverBackup;

$loader->bootstrap($app);
$this->assertFalse(config('hyde.pretty_urls'));
}
}