diff --git a/composer.json b/composer.json index 071e19848..9f611488c 100755 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "illuminate/cache": "^13", "illuminate/collections": "^13", "illuminate/conditionable": "^13", + "illuminate/config": "^13", "illuminate/console": "^13", "illuminate/container": "^13", "illuminate/contracts": "^13", @@ -59,7 +60,6 @@ }, "replace": { "illuminate/auth": "self.version", - "illuminate/config": "self.version", "illuminate/exception": "self.version", "illuminate/foundation": "self.version", "illuminate/hashing": "self.version", diff --git a/src/Illuminate/Foundation/start.php b/src/Illuminate/Foundation/start.php index cfa4f47a4..6d0ff0230 100755 --- a/src/Illuminate/Foundation/start.php +++ b/src/Illuminate/Foundation/start.php @@ -130,11 +130,23 @@ | */ -$app->instance('config', $config = new Config( +// v13 Config\Repository takes a pre-loaded array (no loader/env-cascade). Keep the +// fork FileLoader for the L4.2 env-cascade + eagerly load every group into the array. +$loader = $app->getConfigLoader(); + +$groups = []; +foreach (array_merge( + glob($app['path'].'/config/*.php'), + glob($app['path'].'/config/'.$env.'/*.php') +) as $file) +{ + $groups[basename($file, '.php')] = true; +} - $app->getConfigLoader(), $env +$items = array(); +foreach (array_keys($groups) as $group) $items[$group] = $loader->load($env, $group); -)); +$app->instance('config', $config = new Config($items)); /* |-------------------------------------------------------------------------- diff --git a/tests/CachedRouting/RoutingIntegrationTest.php b/tests/CachedRouting/RoutingIntegrationTest.php index 7776713f7..ee0152269 100755 --- a/tests/CachedRouting/RoutingIntegrationTest.php +++ b/tests/CachedRouting/RoutingIntegrationTest.php @@ -84,14 +84,7 @@ protected function refreshApplication(): void $this->app['path.storage'] = __DIR__; - $loader = $this->createMock('Illuminate\Config\LoaderInterface'); - - $loader->method('load')->willReturn([]); - $loader->method('exists')->willReturn(true); - $loader->method('getNamespaces')->willReturn([]); - $loader->method('cascadePackage')->willReturn([]); - - $this->app['config'] = new Repository($loader, $this->app['env']); + $this->app['config'] = new Repository(); $this->app['files'] = new Filesystem; $this->app['cache'] = new CacheManager($this->app); diff --git a/tests/Config/ConfigRepositoryTest.php b/tests/Config/ConfigRepositoryTest.php deleted file mode 100755 index 60542dc1b..000000000 --- a/tests/Config/ConfigRepositoryTest.php +++ /dev/null @@ -1,156 +0,0 @@ -getRepository(); - $config->getLoader()->shouldReceive('exists')->once()->with('group', 'namespace')->andReturn(false); - $this->assertFalse($config->hasGroup('namespace::group')); - } - - - public function testHasOnTrueReturnsTrue() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options); - - $this->assertTrue($config->has('app.bing')); - $this->assertTrue($config->get('app.bing')); - } - - - public function testGetReturnsBasicItems() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options); - - $this->assertEquals('bar', $config->get('app.foo')); - $this->assertEquals('breeze', $config->get('app.baz.boom')); - $this->assertEquals('blah', $config->get('app.code', 'blah')); - $this->assertEquals('blah', $config->get('app.code', function() { return 'blah'; })); - } - - - public function testEntireArrayCanBeReturned() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'app', null)->andReturn($options); - - $this->assertEquals($options, $config->get('app')); - } - - - public function testLoaderGetsCalledCorrectForNamespaces() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'options', 'namespace')->andReturn($options); - - $this->assertEquals('bar', $config->get('namespace::options.foo')); - $this->assertEquals('breeze', $config->get('namespace::options.baz.boom')); - $this->assertEquals('blah', $config->get('namespace::options.code', 'blah')); - $this->assertEquals('blah', $config->get('namespace::options.code', function() { return 'blah'; })); - } - - - public function testNamespacedAccessedAndPostNamespaceLoadEventIsFired() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'options', 'namespace')->andReturn($options); - $config->afterLoading('namespace', function($repository, $group, $items) - { - $items['dayle'] = 'rees'; - return $items; - }); - - $this->assertEquals('bar', $config->get('namespace::options.foo')); - $this->assertEquals('breeze', $config->get('namespace::options.baz.boom')); - $this->assertEquals('blah', $config->get('namespace::options.code', 'blah')); - $this->assertEquals('blah', $config->get('namespace::options.code', function() { return 'blah'; })); - $this->assertEquals('rees', $config->get('namespace::options.dayle')); - } - - - public function testLoaderUsesNamespaceAsGroupWhenUsingPackagesAndGroupDoesntExist() - { - $config = $this->getRepository(); - $options = $this->getDummyOptions(); - $config->getLoader()->shouldReceive('addNamespace')->with('namespace', __DIR__); - $config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function($env, $package, $group, $items) { return $items; }); - $config->getLoader()->shouldReceive('exists')->once()->with('foo', 'namespace')->andReturn(false); - $config->getLoader()->shouldReceive('exists')->once()->with('baz', 'namespace')->andReturn(false); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'config', 'namespace')->andReturn($options); - - $config->package('foo/namespace', __DIR__); - $this->assertEquals('bar', $config->get('namespace::foo')); - $this->assertEquals('breeze', $config->get('namespace::baz.boom')); - } - - - public function testItemsCanBeSet() - { - $config = $this->getRepository(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'foo', null)->andReturn( - ['name' => 'dayle'] - ); - - $config->set('foo.name', 'taylor'); - $this->assertEquals('taylor', $config->get('foo.name')); - - $config = $this->getRepository(); - $config->getLoader()->shouldReceive('load')->once()->with('production', 'foo', 'namespace')->andReturn( - ['name' => 'dayle'] - ); - - $config->set('namespace::foo.name', 'taylor'); - $this->assertEquals('taylor', $config->get('namespace::foo.name')); - } - - - public function testPackageRegistersNamespaceAndSetsUpAfterLoadCallback() - { - $config = $this->getMock(Repository::class, ['addNamespace'], [ - m::mock( - LoaderInterface::class - ), 'production' - ]); - $config->expects($this->once())->method('addNamespace')->with($this->equalTo('rees'), $this->equalTo(__DIR__)); - $config->getLoader()->shouldReceive('cascadePackage')->once()->with('production', 'dayle/rees', 'group', ['foo'] - )->andReturn(['bar']); - $config->package('dayle/rees', __DIR__); - $afterLoad = $config->getAfterLoadCallbacks(); - $results = call_user_func($afterLoad['rees'], $config, 'group', ['foo']); - - $this->assertEquals(['bar'], $results); - } - - - protected function getRepository() - { - return new Illuminate\Config\Repository(m::mock(LoaderInterface::class), 'production'); - } - - - protected function getDummyOptions() - { - return ['foo' => 'bar', 'baz' => ['boom' => 'breeze'], 'bing' => true]; - } - -}