Passed
Push — master ( dcf026...963312 )
by Caen
03:39 queued 14s
created

LoadConfiguration::getConfigurationFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Internal;
6
7
use Illuminate\Contracts\Config\Repository as RepositoryContract;
8
use Illuminate\Contracts\Foundation\Application;
9
use Illuminate\Foundation\Bootstrap\LoadConfiguration as BaseLoadConfiguration;
10
11
/** @internal */
12
class LoadConfiguration extends BaseLoadConfiguration
13
{
14
    /** Get all the configuration files for the application. */
15
    protected function getConfigurationFiles(Application $app): array
16
    {
17
        return tap(parent::getConfigurationFiles($app), function (array &$files) use ($app): void {
18
            // Inject our custom config file which is stored in `app/config.php`.
19
            $files['app'] = $app->basePath().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'config.php';
20
        });
21
    }
22
23
    /** Load the configuration items from all the files. */
24
    protected function loadConfigurationFiles(Application $app, RepositoryContract $repository): void
25
    {
26
        parent::loadConfigurationFiles($app, $repository);
27
28
        $this->mergeConfigurationFiles($repository, ['view', 'cache', 'commands', 'torchlight']);
29
    }
30
31
    /** These files do commonly not need to be customized by the user, so to get them out of the way, we don't include them in the default project install. */
32
    protected function mergeConfigurationFiles(RepositoryContract $repository, array $keys): void
33
    {
34
        foreach ($keys as $key) {
35
            $this->mergeConfigurationFile($repository, $key);
36
        }
37
    }
38
39
    /** We of course want the user to be able to customize the config files, if they're present, so we'll merge their changes here. */
40
    protected function mergeConfigurationFile(RepositoryContract $repository, string $key): void
41
    {
42
        $repository->set($key, array_merge(
43
            require __DIR__."/../../../config/$key.php",
44
            $repository->get($key, [])
45
        ));
46
    }
47
}
48