summaryrefslogtreecommitdiff
path: root/src/Config/ConfigServiceProvider.php
blob: 63f43cedf1f7bd0074cd9c1d54d11e721c31228b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace Engelsystem\Config;

use Engelsystem\Container\ServiceProvider;
use Exception;

class ConfigServiceProvider extends ServiceProvider
{
    /** @var array */
    protected $configFiles = ['config.default.php', 'config.php'];

    public function register()
    {
        $config = $this->app->make(Config::class);
        $this->app->instance(Config::class, $config);
        $this->app->instance('config', $config);

        foreach ($this->configFiles as $file) {
            $file = config_path($file);

            if (!file_exists($file)) {
                continue;
            }

            $config->set(array_replace_recursive(
                $config->get(null),
                require $file
            ));
        }

        if (empty($config->get(null))) {
            throw new Exception('Configuration not found');
        }
    }
}