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 Illuminate\Contracts\Bus\SelfHandling; |
7
|
|
|
use Illuminate\Contracts\Config\Repository; |
8
|
|
|
use Illuminate\Contracts\Foundation\Application; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ConfigureSystem |
12
|
|
|
* |
13
|
|
|
* @link http://pyrocms.com/ |
14
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
15
|
|
|
* @author Ryan Thompson <[email protected]> |
16
|
|
|
* @package Anomaly\SettingsModule\Setting\Command |
17
|
|
|
*/ |
18
|
|
|
class ConfigureSystem implements SelfHandling |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Configuration to setting map. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $settings = [ |
27
|
|
|
'mail.driver' => 'streams::mail_driver', |
28
|
|
|
'mail.host' => 'streams::mail_host', |
29
|
|
|
'mail.port' => 'streams::mail_port', |
30
|
|
|
'mail.username' => 'streams::mail_username', |
31
|
|
|
'mail.password' => 'streams::mail_password', |
32
|
|
|
'mail.pretend' => 'streams::mail_debug' |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Handle the command. |
37
|
|
|
* |
38
|
|
|
* @param SettingRepositoryInterface $settings |
39
|
|
|
* @param AddonCollection $addons |
40
|
|
|
* @param Repository $config |
41
|
|
|
*/ |
42
|
|
|
public function handle( |
43
|
|
|
SettingRepositoryInterface $settings, |
44
|
|
|
AddonCollection $addons, |
45
|
|
|
Repository $config |
46
|
|
|
) { |
47
|
|
|
/* @var Addon $addon */ |
48
|
|
View Code Duplication |
foreach ($addons->withConfig('settings') as $addon) { |
|
|
|
|
49
|
|
|
foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) { |
50
|
|
|
|
51
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
52
|
|
|
continue; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (!isset($setting['replace'])) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!$settings->has($key = $addon->getNamespace($key))) { |
60
|
|
|
continue; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$config->set($setting['replace'], $settings->value($key)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
foreach ($addons->withConfig('settings/settings') as $addon) { |
|
|
|
|
68
|
|
|
foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) { |
69
|
|
|
|
70
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!isset($setting['replace'])) { |
75
|
|
|
continue; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (!$settings->has($key = $addon->getNamespace($key))) { |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$config->set($setting['replace'], $settings->value($key)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
foreach ($config->get('streams::settings/settings') as $key => $setting) { |
87
|
|
|
|
88
|
|
|
if (isset($setting['env']) && env($setting['env']) !== null) { |
89
|
|
|
continue; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (!isset($setting['replace'])) { |
93
|
|
|
continue; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (!$settings->has($key = 'streams::' . $key)) { |
97
|
|
|
continue; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$config->set($setting['replace'], $settings->value($key)); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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.