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

[11.x] Add option to disable merging of base configuration #51579

Merged
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
29 changes: 29 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ class Application extends Container implements ApplicationContract, CachesConfig
*/
protected $namespace;

/**
* Indicates if the framework's base configuration should be merged.
*
* @var bool
*/
protected $mergeFrameworkConfiguration = true;

/**
* The prefixes of absolute cache paths for use during normalization.
*
Expand Down Expand Up @@ -1198,6 +1205,28 @@ public function handleCommand(InputInterface $input)
return $status;
}

/**
* Determine if the framework's base configuration should be merged.
*
* @return bool
*/
public function shouldMergeFrameworkConfiguration()
{
return $this->mergeFrameworkConfiguration;
}

/**
* Indicate that the framework's base configuration should not be merged.
*
* @return $this
*/
public function dontMergeFrameworkConfiguration()
{
$this->mergeFrameworkConfiguration = false;

return $this;
}

/**
* Determine if middleware has been disabled for the application.
*
Expand Down
8 changes: 7 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
{
$files = $this->getConfigurationFiles($app);

$base = $this->getBaseConfiguration();
$shouldMerge = method_exists($app, 'shouldMergeFrameworkConfiguration')
? $app->shouldMergeFrameworkConfiguration()
: true;

$base = $shouldMerge
? $this->getBaseConfiguration()
: [];

foreach (array_diff(array_keys($base), array_keys($files)) as $name => $config) {
$repository->set($name, $config);
Expand Down
29 changes: 29 additions & 0 deletions tests/Foundation/Bootstrap/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Illuminate\Tests\Foundation\Bootstrap;

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
use PHPUnit\Framework\TestCase;

class LoadConfigurationTest extends TestCase
{
public function testLoadsBaseConfiguration()
{
$app = new Application();

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

$this->assertSame('Laravel', $app['config']['app.name']);
}

public function testDontLoadBaseConfiguration()
{
$app = new Application();
$app->dontMergeFrameworkConfiguration();

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

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