Skip to content

Commit

Permalink
[11.x] Fix issue where $name variable in non base config file becom…
Browse files Browse the repository at this point in the history
…es it's key (laravel#52738)

* Prepare example where the `$name` variable becomes the key of the config

* Require path in isolation

* Use arrow function
  • Loading branch information
rojtjo authored Sep 13, 2024
1 parent e2196b1 commit da28aab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
*/
protected function loadConfigurationFile(RepositoryContract $repository, $name, $path, array $base)
{
$config = require $path;
$config = (fn () => require $path)();

if (isset($base[$name])) {
$config = array_merge($base[$name], $config);
Expand Down
11 changes: 11 additions & 0 deletions tests/Foundation/Bootstrap/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ public function testDontLoadBaseConfiguration()

$this->assertNull($app['config']['app.name']);
}

public function testLoadsConfigurationInIsolation()
{
$app = new Application(__DIR__.'/../fixtures');
$app->useConfigPath(__DIR__.'/../fixtures/config');

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

$this->assertNull($app['config']['bar.foo']);
$this->assertSame('bar', $app['config']['custom.foo']);
}
}
7 changes: 7 additions & 0 deletions tests/Foundation/fixtures/config/custom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$name = 'bar';

return [
'foo' => $name,
];

0 comments on commit da28aab

Please sign in to comment.