forked from horde/components
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfigs.php
129 lines (119 loc) · 3.42 KB
/
Configs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Components_Configs:: class represents configuration for the
* Horde component tool.
*
* PHP Version 7
*
* @category Horde
* @package Components
* @author Gunnar Wrobel <[email protected]>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
namespace Horde\Components;
use Horde\Components\Config\Base;
/**
* Components_Configs:: class represents configuration for the
* Horde component tool.
*
* Copyright 2009-2020 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Components
* @author Gunnar Wrobel <[email protected]>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
class Configs extends Base
{
/**
* The different configuration handlers.
*/
private array $_configs = [];
/**
* Have the arguments been collected?
*/
private bool $_collected = false;
/**
* Constructor.
*/
public function __construct()
{
}
/**
* Add a configuration type to the configuration handler.
*
* @param Config $type The configuration type.
*/
public function addConfigurationType(Config $type): void
{
$this->_configs[] = $type;
}
/**
* Store a configuration type at the start of the configuration stack. Any
* options provided by the new configuration can/will be overridden by
* configurations already present.
*
* @param Config $type The configuration type.
*/
public function unshiftConfigurationType(Config $type): void
{
array_unshift($this->_configs, $type);
}
/**
* Provide each configuration handler with the list of supported modules.
*
* @param Modules $modules A list of modules.
*/
public function handleModules(Modules $modules): void
{
foreach ($this->_configs as $config) {
$config->handleModules($modules);
}
}
/**
* Return the options provided by the configuration handlers.
*
* @return array An array of options.
*/
public function getOptions(): array
{
$options = [];
foreach ($this->_configs as $config) {
if ((is_countable($config->getOptions()) ? count($config->getOptions()) : 0) !== 0) {
$config_options = [];
foreach ($config->getOptions() as $name => $option) {
if ($option !== null) {
$config_options[$name] = $option;
}
}
$options = array_merge($options, $config_options);
}
}
$options = array_merge($options, $this->_options);
return $options;
}
/**
* Return the arguments provided by the configuration handlers.
*
* @return array An array of arguments.
*/
public function getArguments(): array
{
if (!$this->_collected) {
foreach ($this->_configs as $config) {
$config_arguments = $config->getArguments();
if (!empty($config_arguments)) {
$this->_arguments = array_merge(
$this->_arguments,
$config_arguments
);
}
}
$this->_collected = true;
}
return $this->_arguments;
}
}