engelsystem/src/Config/ConfigServiceProvider.php

37 lines
864 B
PHP
Raw Normal View History

2017-10-31 13:40:13 +01:00
<?php
namespace Engelsystem\Config;
use Engelsystem\Container\ServiceProvider;
use Exception;
2017-10-31 13:40:13 +01:00
class ConfigServiceProvider extends ServiceProvider
{
/** @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);
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),
require $file
2017-10-31 13:40:13 +01:00
));
}
if (empty($config->get(null))) {
throw new Exception('Configuration not found');
}
2017-10-31 13:40:13 +01:00
}
}