1
|
|
|
<?php namespace Anomaly\SettingsModule\Setting\Command; |
2
|
|
|
|
3
|
|
|
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface; |
4
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
5
|
|
|
use Anomaly\Streams\Platform\Addon\AddonCollection; |
6
|
|
|
use Anomaly\Streams\Platform\Support\Evaluator; |
7
|
|
|
use Illuminate\Contracts\Config\Repository; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ConfigureSystem |
11
|
|
|
* |
12
|
|
|
* @link http://pyrocms.com/ |
13
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
14
|
|
|
* @author Ryan Thompson <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ConfigureSystem |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Handle the command. |
21
|
|
|
* |
22
|
|
|
* @param SettingRepositoryInterface $settings |
23
|
|
|
* @param AddonCollection $addons |
24
|
|
|
* @param Evaluator $evaluator |
25
|
|
|
* @param Repository $config |
26
|
|
|
*/ |
27
|
|
|
public function handle( |
28
|
|
|
SettingRepositoryInterface $settings, |
29
|
|
|
AddonCollection $addons, |
30
|
|
|
Evaluator $evaluator, |
31
|
|
|
Repository $config |
32
|
|
|
) { |
33
|
|
|
/* @var Addon $addon */ |
34
|
|
View Code Duplication |
foreach ($addons->withConfig('settings') as $addon) { |
|
|
|
|
35
|
|
|
foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) { |
36
|
|
|
|
37
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
38
|
|
|
continue; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (!isset($setting['bind'])) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$default = array_get($setting, 'config.default_value'); |
46
|
|
|
|
47
|
|
|
if (!$settings->has($key = $addon->getNamespace($key)) && !$default) { |
48
|
|
|
continue; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($presenter = $settings->presenter($key)) { |
52
|
|
|
|
53
|
|
|
$config->set($setting['bind'], $presenter->__value()); |
54
|
|
|
|
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$config->set($setting['bind'], $evaluator->evaluate($default)); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
foreach ($addons->withConfig('settings/settings') as $addon) { |
|
|
|
|
63
|
|
|
foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) { |
64
|
|
|
|
65
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (!isset($setting['bind'])) { |
70
|
|
|
continue; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$default = array_get($setting, 'config.default_value'); |
74
|
|
|
|
75
|
|
|
if (!$settings->has($key = $addon->getNamespace($key)) && !$default) { |
76
|
|
|
continue; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($presenter = $settings->presenter($key)) { |
80
|
|
|
|
81
|
|
|
$config->set($setting['bind'], $presenter->__value()); |
82
|
|
|
|
83
|
|
|
continue; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$config->set($setting['bind'], $evaluator->evaluate($default)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
foreach ($config->get('streams::settings/settings', []) as $key => $setting) { |
91
|
|
|
|
92
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
93
|
|
|
continue; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (!isset($setting['bind'])) { |
97
|
|
|
continue; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$default = array_get($setting, 'config.default_value'); |
101
|
|
|
|
102
|
|
|
if (!$settings->has($key = 'streams::' . $key) && !$default) { |
103
|
|
|
continue; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ($presenter = $settings->presenter($key)) { |
107
|
|
|
|
108
|
|
|
$config->set($setting['bind'], $presenter->__value()); |
109
|
|
|
|
110
|
|
|
continue; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$config->set($setting['bind'], $evaluator->evaluate($default)); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.