|
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
|
|
|
|