2017-10-31 13:40:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Config;
|
|
|
|
|
|
|
|
use Engelsystem\Container\ServiceProvider;
|
2018-08-10 15:02:07 +02:00
|
|
|
use Exception;
|
2017-10-31 13:40:13 +01:00
|
|
|
|
|
|
|
class ConfigServiceProvider extends ServiceProvider
|
|
|
|
{
|
2018-08-10 15:02:07 +02:00
|
|
|
/** @var array */
|
|
|
|
protected $configFiles = ['config.default.php', 'config.php'];
|
|
|
|
|
2017-10-31 13:40:13 +01:00
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
$config = $this->app->make(Config::class);
|
2018-08-26 12:23:47 +02:00
|
|
|
$this->app->instance(Config::class, $config);
|
2017-10-31 13:40:13 +01:00
|
|
|
$this->app->instance('config', $config);
|
|
|
|
|
2018-08-10 15:02:07 +02:00
|
|
|
foreach ($this->configFiles as $file) {
|
|
|
|
$file = config_path($file);
|
|
|
|
|
|
|
|
if (!file_exists($file)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-31 13:40:13 +01:00
|
|
|
|
|
|
|
$config->set(array_replace_recursive(
|
|
|
|
$config->get(null),
|
2018-08-10 15:02:07 +02:00
|
|
|
require $file
|
2017-10-31 13:40:13 +01:00
|
|
|
));
|
|
|
|
}
|
2018-08-10 15:02:07 +02:00
|
|
|
|
|
|
|
if (empty($config->get(null))) {
|
|
|
|
throw new Exception('Configuration not found');
|
|
|
|
}
|
2017-10-31 13:40:13 +01:00
|
|
|
}
|
|
|
|
}
|