summaryrefslogtreecommitdiff
path: root/src/Config/ConfigServiceProvider.php
blob: 9fbccd680f674166b058f1c0432a9b64ca6ed26d (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
<?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', $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');
        }
    }
}