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 2 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
5 changes: 5 additions & 0 deletions src/Illuminate/Contracts/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public function setLocale($locale);
*/
public function shouldSkipMiddleware();

/**
* @return bool
*/
public function shouldMergeBaseConfiguration();
driesvints marked this conversation as resolved.
Show resolved Hide resolved

/**
* Register a terminating callback with the application.
*
Expand Down
23 changes: 23 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class Application extends Container implements ApplicationContract, CachesConfig
*/
protected $absoluteCachePathPrefixes = ['/', '\\'];

/**
* @var bool
*/
protected $mergeBaseConfiguration = true;

/**
* Create a new Illuminate application instance.
*
Expand Down Expand Up @@ -1209,6 +1214,24 @@ public function shouldSkipMiddleware()
$this->make('middleware.disable') === true;
}

/**
* @return $this
*/
public function dontMergeBaseConfiguration()
{
$this->mergeBaseConfiguration = false;

return $this;
}

/**
* @return bool
*/
public function shouldMergeBaseConfiguration()
{
return $this->mergeBaseConfiguration;
}

/**
* Get the path to the cached services.php file.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
// throw new Exception('Unable to load the "app" configuration file.');
// }

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

foreach ($files as $name => $path) {
$base = $this->loadConfigurationFile($repository, $name, $path, $base);
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->dontMergeBaseConfiguration();

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

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