Skip to content

Commit

Permalink
Allow config to be stored in subdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Feb 16, 2015
1 parent b1aea04 commit fee9820
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Config\Repository;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Config\Repository as RepositoryContract;

Expand Down Expand Up @@ -69,10 +70,26 @@ protected function getConfigurationFiles(Application $app)

foreach (Finder::create()->files()->name('*.php')->in($app->configPath()) as $file)
{
$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
$files[$this->getConfigurationSubtree($file).basename($file->getRealPath(), '.php')] = $file->getRealPath();

This comment has been minimized.

Copy link
@mpociot

mpociot Feb 26, 2015

Contributor

This breaks current configurations.
For example, I had a config file in the "packages" directory.

I was using Config::get('my_cfg_file.key') which is suddenly broken, because it now needs to be: Config::get('packages.my_cfg_file.key')

This comment has been minimized.

Copy link
@antonioribeiro

antonioribeiro Feb 26, 2015

Author Contributor

Unfortunatelly in this case, yes it will break, because now if you have your config in subdirs you'll have to get them accordingly to your config tree. Imo, it made no sense have config in subdirs and get them all via config's root tree.

The problem was, if you had a file

/var/www/project/config/packages/oauth.php

And an oauth package installed in your application, which would also have a config at:

/var/www/project/config/oauth.php

When using

Config::get('oauth.key')

Keys could conflict, or worse, being lost. But now you know you will use

Config::get('packages.oauth.key')

For yours, and

Config::get('oauth.key')

For the oauth package.

This comment has been minimized.

Copy link
@GrahamCampbell

GrahamCampbell Feb 26, 2015

Member

Basically, this is not a breaking change. It only appears that way if you were using it wrong in the first place.

}

return $files;
}

/**
* Get the configuration file subtree.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @return string
*/
private function getConfigurationSubtree(SplFileInfo $file)
{
if ($tree = ltrim(dirname($file->getRealPath()), config_path()))
{
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
}

return $tree;
}

}

0 comments on commit fee9820

Please sign in to comment.