<?php
namespace Illuminate\Foundation\Bootstrap;
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;
class LoadConfiguration
{
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
$items = [];
if (file_exists($cached = $app->getCachedConfigPath())) {
$items = require $cached;
$loadedFromCache = true;
}
$app->instance('config', $config = new Repository($items));
if (! isset($loadedFromCache)) {
$this->loadConfigurationFiles($app, $config);
}
date_default_timezone_set($config['app.timezone']);
mb_internal_encoding('UTF-8');
}
* Load the configuration items from all of the files.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Config\Repository $repository
* @return void
*/
protected function loadConfigurationFiles(Application $app, RepositoryContract $repository)
{
foreach ($this->getConfigurationFiles($app) as $key => $path) {
$repository->set($key, require $path);
}
}
* Get all of the configuration files for the application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return array
*/
protected function getConfigurationFiles(Application $app)
{
$files = [];
$configPath = realpath($app->configPath());
foreach (Finder::create()->files()->name('*.php')->in($configPath) as $file) {
$nesting = $this->getConfigurationNesting($file, $configPath);
$files[$nesting.basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
return $files;
}
* Get the configuration file nesting path.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @param string $configPath
* @return string
*/
protected function getConfigurationNesting(SplFileInfo $file, $configPath)
{
$directory = dirname($file->getRealPath());
if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) {
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree).'.';
}
return $tree;
}
}