<?phpnamespaceApp\Http\Bootstrap;useSymfony\Component\Finder\Finder;useSymfony\Component\Finder\SplFileInfo;useIlluminate\Contracts\Foundation\Application;useIlluminate\Contracts\Config\Repositoryas RepositoryContract;classLoadSiteConfiguration{/**
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/publicfunctionbootstrap(Application $app){// First we will see if we have a cache configuration file. If we do, we'll load// the configuration items from that file so that it is very quick. Otherwise// we will need to spin through every configuration file and load them all.if(file_exists($cached=$app->getCachedConfigPath())){return;}// Next we will spin through all of the configuration files in the configuration// directory and load each one into the repository. This will make all of the// options available to the developer for use in various parts of this app.$config=app('config');if(!isset($loadedFromCache)&&env('APP_ENV')!='production'){$this->loadConfigurationFiles($app,$config);}}/**
* Load the configuration items from all of the files.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Config\Repository $config
* @return void
*/protectedfunctionloadConfigurationFiles(Application $app, RepositoryContract $config){$siteConfig=[];foreach($this->getConfigurationFiles($app)as$key=>$path){array_set($siteConfig,$key,require$path);}$siteConfig=array_dot($siteConfig);foreach($siteConfigas$key=>$value){$config->set($key,$value);}}/**
* Get all of the configuration files for the application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return array
*/protectedfunctiongetConfigurationFiles(Application $app){$files=[];$env=env('APP_ENV','production');$configPath=realpath($app->configPath());if($env!='production'){$configPath=$configPath.DIRECTORY_SEPARATOR.$env;}if(!is_dir($configPath)){return[];}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
*/protectedfunctiongetConfigurationNesting(SplFileInfo $file,$configPath){$directory=dirname($file->getRealPath());if($tree=trim(str_replace($configPath,'',$directory),DIRECTORY_SEPARATOR)){$tree=str_replace(DIRECTORY_SEPARATOR,'.',$tree).'.';}return$tree;}}