Passed
Push — master ( e01b5f...9c811f )
by Attila
08:21
created

getCascadeModuleConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Contains the BaseBoxServiceProvider class.
4
 *
5
 * @copyright   Copyright (c) 2016 Attila Fulop
6
 * @author      Attila Fulop
7
 * @license     MIT
8
 * @since       2016-12-29
9
 *
10
 */
11
12
namespace Konekt\Concord;
13
14
abstract class BaseBoxServiceProvider extends BaseServiceProvider
15
{
16
    protected $configFileName = 'box.php';
17
18
    protected static $_kind = 'box';
19
20
    public function register()
21
    {
22
        parent::register();
23
24
        $modules = $this->config("modules");
25
        $modules = $modules ?: [];
26
27
        foreach ($modules as $module => $configuration) {
28
            if (is_int($module) && is_string($configuration)) { // means no configuration was set for module
29
                $module        = $configuration;
30
                $configuration = $this->getDefaultModuleConfiguration();
31
            } else {
32
                $configuration = array_merge($this->getDefaultModuleConfiguration(),
33
                    is_array($configuration) ? $configuration : []);
34
                $configuration = array_replace_recursive($configuration, $this->getCascadeModuleConfiguration());
35
            }
36
37
            $this->concord->registerModule($module, $configuration);
38
        }
39
    }
40
41
    /**
42
     * Returns the "cascade" configuration: the "apply to all submodules" config override array
43
     *
44
     * @return array
45
     */
46
    protected function getCascadeModuleConfiguration(): array
47
    {
48
        $result = $this->config('cascade_config', []);
49
50
        return is_array($result) ? $result : [];
51
    }
52
53
    /**
54
     * Returns the default configuration settings for modules loaded within boxes
55
     *
56
     * @return array
57
     */
58
    protected function getDefaultModuleConfiguration()
59
    {
60
        return [
61
            'implicit'   => true,
62
            'migrations' => $this->areMigrationsEnabled(),
63
            'views'      => $this->areViewsEnabled(),
64
            'routes'     => $this->areRoutesEnabled()
65
        ];
66
    }
67
}
68