@@ -22,30 +22,30 @@ |
||
22 | 22 | interface ConfigSchemaInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Get the set of defined options. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @return array|null |
|
31 | - */ |
|
32 | - public function getDefinedOptions(); |
|
25 | + /** |
|
26 | + * Get the set of defined options. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @return array|null |
|
31 | + */ |
|
32 | + public function getDefinedOptions(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get the set of default options. |
|
36 | - * |
|
37 | - * @since 0.1.0 |
|
38 | - * |
|
39 | - * @return array|null |
|
40 | - */ |
|
41 | - public function getDefaultOptions(); |
|
34 | + /** |
|
35 | + * Get the set of default options. |
|
36 | + * |
|
37 | + * @since 0.1.0 |
|
38 | + * |
|
39 | + * @return array|null |
|
40 | + */ |
|
41 | + public function getDefaultOptions(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the set of required options. |
|
45 | - * |
|
46 | - * @since 0.1.0 |
|
47 | - * |
|
48 | - * @return array|null |
|
49 | - */ |
|
50 | - public function getRequiredOptions(); |
|
43 | + /** |
|
44 | + * Get the set of required options. |
|
45 | + * |
|
46 | + * @since 0.1.0 |
|
47 | + * |
|
48 | + * @return array|null |
|
49 | + */ |
|
50 | + public function getRequiredOptions(); |
|
51 | 51 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | interface ConfigValidatorInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Check whether the passed-in Config is valid. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @param ConfigInterface $config |
|
31 | - * |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function isValid(ConfigInterface $config); |
|
25 | + /** |
|
26 | + * Check whether the passed-in Config is valid. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @param ConfigInterface $config |
|
31 | + * |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function isValid(ConfigInterface $config); |
|
35 | 35 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -24,80 +24,80 @@ discard block |
||
24 | 24 | class ConfigFactory |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Create a new ConfigInterface object from a file. |
|
29 | - * |
|
30 | - * If a comma-separated list of files is provided, they are checked in sequence until the first one could be loaded |
|
31 | - * successfully. |
|
32 | - * |
|
33 | - * @since 0.3.0 |
|
34 | - * |
|
35 | - * @param string|array $_ List of files. |
|
36 | - * |
|
37 | - * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
38 | - */ |
|
39 | - public static function createFromFile($_) |
|
40 | - { |
|
41 | - $files = array_reverse(func_get_args()); |
|
27 | + /** |
|
28 | + * Create a new ConfigInterface object from a file. |
|
29 | + * |
|
30 | + * If a comma-separated list of files is provided, they are checked in sequence until the first one could be loaded |
|
31 | + * successfully. |
|
32 | + * |
|
33 | + * @since 0.3.0 |
|
34 | + * |
|
35 | + * @param string|array $_ List of files. |
|
36 | + * |
|
37 | + * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
38 | + */ |
|
39 | + public static function createFromFile($_) |
|
40 | + { |
|
41 | + $files = array_reverse(func_get_args()); |
|
42 | 42 | |
43 | - if (is_array($files[0])) { |
|
44 | - $files = $files[0]; |
|
45 | - } |
|
43 | + if (is_array($files[0])) { |
|
44 | + $files = $files[0]; |
|
45 | + } |
|
46 | 46 | |
47 | - while (count($files) > 0) { |
|
48 | - try { |
|
49 | - $file = array_pop($files); |
|
47 | + while (count($files) > 0) { |
|
48 | + try { |
|
49 | + $file = array_pop($files); |
|
50 | 50 | |
51 | - if (! file_exists($file)) { |
|
52 | - continue; |
|
53 | - } |
|
51 | + if (! file_exists($file)) { |
|
52 | + continue; |
|
53 | + } |
|
54 | 54 | |
55 | - return new Config(include $file); |
|
56 | - } catch (Exception $exception) { |
|
55 | + return new Config(include $file); |
|
56 | + } catch (Exception $exception) { |
|
57 | 57 | |
58 | - } |
|
59 | - } |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - return new Config([]); |
|
62 | - } |
|
61 | + return new Config([]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Create a new ConfigInterface object from an array. |
|
66 | - * |
|
67 | - * @since 0.3.0 |
|
68 | - * |
|
69 | - * @param array $array Array with configuration values. |
|
70 | - * |
|
71 | - * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
72 | - */ |
|
73 | - public static function createFromArray(array $array) |
|
74 | - { |
|
75 | - return new Config($array); |
|
76 | - } |
|
64 | + /** |
|
65 | + * Create a new ConfigInterface object from an array. |
|
66 | + * |
|
67 | + * @since 0.3.0 |
|
68 | + * |
|
69 | + * @param array $array Array with configuration values. |
|
70 | + * |
|
71 | + * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
72 | + */ |
|
73 | + public static function createFromArray(array $array) |
|
74 | + { |
|
75 | + return new Config($array); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Create a new ConfigInterface object. |
|
80 | - * |
|
81 | - * Tries to deduce the correct creation method by inspecting the provided arguments. |
|
82 | - * |
|
83 | - * @since 0.3.0 |
|
84 | - * |
|
85 | - * @param mixed $_ Array with configuration values. |
|
86 | - * |
|
87 | - * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
88 | - */ |
|
89 | - public static function create($_) |
|
90 | - { |
|
91 | - if (func_num_args() < 1) { |
|
92 | - return new Config([]); |
|
93 | - } |
|
78 | + /** |
|
79 | + * Create a new ConfigInterface object. |
|
80 | + * |
|
81 | + * Tries to deduce the correct creation method by inspecting the provided arguments. |
|
82 | + * |
|
83 | + * @since 0.3.0 |
|
84 | + * |
|
85 | + * @param mixed $_ Array with configuration values. |
|
86 | + * |
|
87 | + * @return ConfigInterface Instance of a ConfigInterface implementation. |
|
88 | + */ |
|
89 | + public static function create($_) |
|
90 | + { |
|
91 | + if (func_num_args() < 1) { |
|
92 | + return new Config([]); |
|
93 | + } |
|
94 | 94 | |
95 | - $arguments = func_get_args(); |
|
95 | + $arguments = func_get_args(); |
|
96 | 96 | |
97 | - if (is_array($arguments[0]) && func_num_args() === 1) { |
|
98 | - return self::createFromArray($arguments[0]); |
|
99 | - } |
|
97 | + if (is_array($arguments[0]) && func_num_args() === 1) { |
|
98 | + return self::createFromArray($arguments[0]); |
|
99 | + } |
|
100 | 100 | |
101 | - return self::createFromFile($arguments); |
|
102 | - } |
|
101 | + return self::createFromFile($arguments); |
|
102 | + } |
|
103 | 103 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | try { |
49 | 49 | $file = array_pop($files); |
50 | 50 | |
51 | - if (! file_exists($file)) { |
|
51 | + if ( ! file_exists($file)) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | 54 |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -28,231 +28,231 @@ discard block |
||
28 | 28 | abstract class AbstractConfig extends ArrayObject implements ConfigInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Array of strings that are used as delimiters to parse configuration keys. |
|
33 | - * |
|
34 | - * @since 0.1.6 |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $delimiter = ['\\', '/', '.']; |
|
31 | + /** |
|
32 | + * Array of strings that are used as delimiters to parse configuration keys. |
|
33 | + * |
|
34 | + * @since 0.1.6 |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $delimiter = ['\\', '/', '.']; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Instantiate the AbstractConfig object. |
|
42 | - * |
|
43 | - * @since 0.1.0 |
|
44 | - * @since 0.1.6 Accepts a delimiter to parse configuration keys. |
|
45 | - * |
|
46 | - * @param array $config Array with settings. |
|
47 | - * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse |
|
48 | - * configuration keys. Defaults to "\", "/" & ".". |
|
49 | - */ |
|
50 | - public function __construct(array $config, $delimiter = null) |
|
51 | - { |
|
52 | - // Make sure the config entries can be accessed as properties. |
|
53 | - parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); |
|
40 | + /** |
|
41 | + * Instantiate the AbstractConfig object. |
|
42 | + * |
|
43 | + * @since 0.1.0 |
|
44 | + * @since 0.1.6 Accepts a delimiter to parse configuration keys. |
|
45 | + * |
|
46 | + * @param array $config Array with settings. |
|
47 | + * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse |
|
48 | + * configuration keys. Defaults to "\", "/" & ".". |
|
49 | + */ |
|
50 | + public function __construct(array $config, $delimiter = null) |
|
51 | + { |
|
52 | + // Make sure the config entries can be accessed as properties. |
|
53 | + parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); |
|
54 | 54 | |
55 | - if (null !== $delimiter) { |
|
56 | - $this->delimiter = (array)$delimiter; |
|
57 | - } |
|
58 | - } |
|
55 | + if (null !== $delimiter) { |
|
56 | + $this->delimiter = (array)$delimiter; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Get the value of a specific key. |
|
62 | - * |
|
63 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
64 | - * |
|
65 | - * @since 0.1.0 |
|
66 | - * @since 0.1.4 Accepts list of keys. |
|
67 | - * |
|
68 | - * @param string|array $_ List of keys. |
|
69 | - * |
|
70 | - * @return mixed |
|
71 | - * @throws BadMethodCallException If no argument was provided. |
|
72 | - * @throws OutOfRangeException If an unknown key is requested. |
|
73 | - */ |
|
74 | - public function getKey($_) |
|
75 | - { |
|
76 | - $keys = $this->validateKeys(func_get_args()); |
|
60 | + /** |
|
61 | + * Get the value of a specific key. |
|
62 | + * |
|
63 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
64 | + * |
|
65 | + * @since 0.1.0 |
|
66 | + * @since 0.1.4 Accepts list of keys. |
|
67 | + * |
|
68 | + * @param string|array $_ List of keys. |
|
69 | + * |
|
70 | + * @return mixed |
|
71 | + * @throws BadMethodCallException If no argument was provided. |
|
72 | + * @throws OutOfRangeException If an unknown key is requested. |
|
73 | + */ |
|
74 | + public function getKey($_) |
|
75 | + { |
|
76 | + $keys = $this->validateKeys(func_get_args()); |
|
77 | 77 | |
78 | - $keys = array_reverse($keys); |
|
79 | - $array = $this->getArrayCopy(); |
|
80 | - while (count($keys) > 0) { |
|
81 | - $key = array_pop($keys); |
|
82 | - $array = $array[$key]; |
|
83 | - } |
|
78 | + $keys = array_reverse($keys); |
|
79 | + $array = $this->getArrayCopy(); |
|
80 | + while (count($keys) > 0) { |
|
81 | + $key = array_pop($keys); |
|
82 | + $array = $array[$key]; |
|
83 | + } |
|
84 | 84 | |
85 | - return $array; |
|
86 | - } |
|
85 | + return $array; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Check whether the Config has a specific key. |
|
90 | - * |
|
91 | - * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
92 | - * |
|
93 | - * @since 0.1.0 |
|
94 | - * @since 0.1.4 Accepts list of keys. |
|
95 | - * |
|
96 | - * @param string|array $_ List of keys. |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function hasKey($_) |
|
101 | - { |
|
102 | - try { |
|
103 | - $keys = array_reverse($this->getKeyArguments(func_get_args())); |
|
88 | + /** |
|
89 | + * Check whether the Config has a specific key. |
|
90 | + * |
|
91 | + * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
92 | + * |
|
93 | + * @since 0.1.0 |
|
94 | + * @since 0.1.4 Accepts list of keys. |
|
95 | + * |
|
96 | + * @param string|array $_ List of keys. |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function hasKey($_) |
|
101 | + { |
|
102 | + try { |
|
103 | + $keys = array_reverse($this->getKeyArguments(func_get_args())); |
|
104 | 104 | |
105 | - $array = $this->getArrayCopy(); |
|
106 | - while (count($keys) > 0) { |
|
107 | - $key = array_pop($keys); |
|
108 | - if (! array_key_exists($key, $array)) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - $array = $array[$key]; |
|
112 | - } |
|
113 | - } catch (Exception $exception) { |
|
114 | - return false; |
|
115 | - } |
|
105 | + $array = $this->getArrayCopy(); |
|
106 | + while (count($keys) > 0) { |
|
107 | + $key = array_pop($keys); |
|
108 | + if (! array_key_exists($key, $array)) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + $array = $array[$key]; |
|
112 | + } |
|
113 | + } catch (Exception $exception) { |
|
114 | + return false; |
|
115 | + } |
|
116 | 116 | |
117 | - return true; |
|
118 | - } |
|
117 | + return true; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
122 | - * |
|
123 | - * @since 0.1.4 |
|
124 | - * |
|
125 | - * @return array |
|
126 | - */ |
|
127 | - public function getAll() |
|
128 | - { |
|
129 | - return $this->getArrayCopy(); |
|
130 | - } |
|
120 | + /** |
|
121 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
122 | + * |
|
123 | + * @since 0.1.4 |
|
124 | + * |
|
125 | + * @return array |
|
126 | + */ |
|
127 | + public function getAll() |
|
128 | + { |
|
129 | + return $this->getArrayCopy(); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Get the an array with all the keys |
|
134 | - * |
|
135 | - * @since 0.1.0 |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function getKeys() |
|
139 | - { |
|
140 | - return array_keys((array)$this); |
|
141 | - } |
|
132 | + /** |
|
133 | + * Get the an array with all the keys |
|
134 | + * |
|
135 | + * @since 0.1.0 |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function getKeys() |
|
139 | + { |
|
140 | + return array_keys((array)$this); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get a new config at a specific sub-level. |
|
145 | - * |
|
146 | - * @since 0.1.13 |
|
147 | - * |
|
148 | - * @param string|array $_ List of keys. |
|
149 | - * |
|
150 | - * @return ConfigInterface |
|
151 | - * @throws BadMethodCallException If no argument was provided. |
|
152 | - * @throws OutOfRangeException If an unknown key is requested. |
|
153 | - */ |
|
154 | - public function getSubConfig($_) |
|
155 | - { |
|
156 | - $keys = $this->validateKeys(func_get_args()); |
|
143 | + /** |
|
144 | + * Get a new config at a specific sub-level. |
|
145 | + * |
|
146 | + * @since 0.1.13 |
|
147 | + * |
|
148 | + * @param string|array $_ List of keys. |
|
149 | + * |
|
150 | + * @return ConfigInterface |
|
151 | + * @throws BadMethodCallException If no argument was provided. |
|
152 | + * @throws OutOfRangeException If an unknown key is requested. |
|
153 | + */ |
|
154 | + public function getSubConfig($_) |
|
155 | + { |
|
156 | + $keys = $this->validateKeys(func_get_args()); |
|
157 | 157 | |
158 | - $subConfig = clone $this; |
|
159 | - $subConfig->reduceToSubKey($keys); |
|
158 | + $subConfig = clone $this; |
|
159 | + $subConfig->reduceToSubKey($keys); |
|
160 | 160 | |
161 | - return $subConfig; |
|
162 | - } |
|
161 | + return $subConfig; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Validate a set of keys to make sure they exist. |
|
166 | - * |
|
167 | - * @since 0.1.13 |
|
168 | - * |
|
169 | - * @param string|array $_ List of keys. |
|
170 | - * |
|
171 | - * @return array List of keys. |
|
172 | - * @throws BadMethodCallException If no argument was provided. |
|
173 | - * @throws OutOfRangeException If an unknown key is requested. |
|
174 | - */ |
|
175 | - public function validateKeys($_) |
|
176 | - { |
|
177 | - $keys = $this->getKeyArguments(func_get_args()); |
|
164 | + /** |
|
165 | + * Validate a set of keys to make sure they exist. |
|
166 | + * |
|
167 | + * @since 0.1.13 |
|
168 | + * |
|
169 | + * @param string|array $_ List of keys. |
|
170 | + * |
|
171 | + * @return array List of keys. |
|
172 | + * @throws BadMethodCallException If no argument was provided. |
|
173 | + * @throws OutOfRangeException If an unknown key is requested. |
|
174 | + */ |
|
175 | + public function validateKeys($_) |
|
176 | + { |
|
177 | + $keys = $this->getKeyArguments(func_get_args()); |
|
178 | 178 | |
179 | - Assert\that($keys)->all()->string()->notEmpty(); |
|
179 | + Assert\that($keys)->all()->string()->notEmpty(); |
|
180 | 180 | |
181 | - if (! $this->hasKey($keys)) { |
|
182 | - throw new OutOfRangeException( |
|
183 | - sprintf( |
|
184 | - _('The configuration key %1$s does not exist.'), |
|
185 | - implode('->', $keys) |
|
186 | - ) |
|
187 | - ); |
|
188 | - } |
|
181 | + if (! $this->hasKey($keys)) { |
|
182 | + throw new OutOfRangeException( |
|
183 | + sprintf( |
|
184 | + _('The configuration key %1$s does not exist.'), |
|
185 | + implode('->', $keys) |
|
186 | + ) |
|
187 | + ); |
|
188 | + } |
|
189 | 189 | |
190 | - return $keys; |
|
191 | - } |
|
190 | + return $keys; |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Reduce the currently stored config array to a subarray at a specific level. |
|
195 | - * |
|
196 | - * @since 0.1.13 |
|
197 | - * |
|
198 | - * @param array $keys Array of keys that point to a key down in the hierarchy. |
|
199 | - */ |
|
200 | - protected function reduceToSubKey(array $keys) |
|
201 | - { |
|
202 | - $this->exchangeArray($this->getKey($keys)); |
|
203 | - } |
|
193 | + /** |
|
194 | + * Reduce the currently stored config array to a subarray at a specific level. |
|
195 | + * |
|
196 | + * @since 0.1.13 |
|
197 | + * |
|
198 | + * @param array $keys Array of keys that point to a key down in the hierarchy. |
|
199 | + */ |
|
200 | + protected function reduceToSubKey(array $keys) |
|
201 | + { |
|
202 | + $this->exchangeArray($this->getKey($keys)); |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Recursively extract the configuration key arguments from an arbitrary array. |
|
207 | - * |
|
208 | - * @since 0.1.6 |
|
209 | - * |
|
210 | - * @param array $arguments Array as fetched through get_func_args(). |
|
211 | - * |
|
212 | - * @return array Array of strings. |
|
213 | - * @throws BadMethodCallException If no argument was provided. |
|
214 | - */ |
|
215 | - protected function getKeyArguments($arguments) |
|
216 | - { |
|
217 | - Assert\that($arguments)->isArray()->notEmpty(); |
|
205 | + /** |
|
206 | + * Recursively extract the configuration key arguments from an arbitrary array. |
|
207 | + * |
|
208 | + * @since 0.1.6 |
|
209 | + * |
|
210 | + * @param array $arguments Array as fetched through get_func_args(). |
|
211 | + * |
|
212 | + * @return array Array of strings. |
|
213 | + * @throws BadMethodCallException If no argument was provided. |
|
214 | + */ |
|
215 | + protected function getKeyArguments($arguments) |
|
216 | + { |
|
217 | + Assert\that($arguments)->isArray()->notEmpty(); |
|
218 | 218 | |
219 | - $keys = []; |
|
220 | - foreach ($arguments as $argument) { |
|
221 | - if (is_array($argument)) { |
|
222 | - $keys = array_merge($keys, $this->getKeyArguments($argument)); |
|
223 | - } |
|
224 | - if (is_string($argument)) { |
|
225 | - $keys = array_merge($keys, $this->parseKeysString($argument)); |
|
226 | - } |
|
227 | - } |
|
219 | + $keys = []; |
|
220 | + foreach ($arguments as $argument) { |
|
221 | + if (is_array($argument)) { |
|
222 | + $keys = array_merge($keys, $this->getKeyArguments($argument)); |
|
223 | + } |
|
224 | + if (is_string($argument)) { |
|
225 | + $keys = array_merge($keys, $this->parseKeysString($argument)); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - return $keys; |
|
230 | - } |
|
229 | + return $keys; |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Extract individual keys from a delimited string. |
|
234 | - * |
|
235 | - * @since 0.1.6 |
|
236 | - * |
|
237 | - * @param string $keyString Delimited string of keys. |
|
238 | - * |
|
239 | - * @return array Array of key strings. |
|
240 | - */ |
|
241 | - protected function parseKeysString($keyString) |
|
242 | - { |
|
243 | - Assert\that($keyString)->string()->notEmpty(); |
|
232 | + /** |
|
233 | + * Extract individual keys from a delimited string. |
|
234 | + * |
|
235 | + * @since 0.1.6 |
|
236 | + * |
|
237 | + * @param string $keyString Delimited string of keys. |
|
238 | + * |
|
239 | + * @return array Array of key strings. |
|
240 | + */ |
|
241 | + protected function parseKeysString($keyString) |
|
242 | + { |
|
243 | + Assert\that($keyString)->string()->notEmpty(); |
|
244 | 244 | |
245 | - // Replace all of the configured delimiters by the first one, so that we can then use explode(). |
|
246 | - $normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString); |
|
245 | + // Replace all of the configured delimiters by the first one, so that we can then use explode(). |
|
246 | + $normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString); |
|
247 | 247 | |
248 | - return (array)explode($this->delimiter[0], $normalizedString); |
|
249 | - } |
|
248 | + return (array)explode($this->delimiter[0], $normalizedString); |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * Validate the Config file. |
|
253 | - * |
|
254 | - * @since 0.1.0 |
|
255 | - * @return boolean |
|
256 | - */ |
|
257 | - abstract public function isValid(); |
|
251 | + /** |
|
252 | + * Validate the Config file. |
|
253 | + * |
|
254 | + * @since 0.1.0 |
|
255 | + * @return boolean |
|
256 | + */ |
|
257 | + abstract public function isValid(); |
|
258 | 258 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -31,231 +31,231 @@ discard block |
||
31 | 31 | class Config extends AbstractConfig |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * The schema of the Config file. |
|
36 | - * |
|
37 | - * @var Schema |
|
38 | - */ |
|
39 | - protected $schema; |
|
34 | + /** |
|
35 | + * The schema of the Config file. |
|
36 | + * |
|
37 | + * @var Schema |
|
38 | + */ |
|
39 | + protected $schema; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The Validator class that gets asked to do the validation of the config. |
|
43 | - * |
|
44 | - * @since 0.1.0 |
|
45 | - * |
|
46 | - * @var Validator |
|
47 | - */ |
|
48 | - protected $validator; |
|
41 | + /** |
|
42 | + * The Validator class that gets asked to do the validation of the config. |
|
43 | + * |
|
44 | + * @since 0.1.0 |
|
45 | + * |
|
46 | + * @var Validator |
|
47 | + */ |
|
48 | + protected $validator; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Instantiate the Config object. |
|
52 | - * |
|
53 | - * It accepts either an array with the configuration settings, or a |
|
54 | - * filename pointing to a PHP file it can include. |
|
55 | - * |
|
56 | - * @since 0.1.0 |
|
57 | - * @since 0.1.6 Accepts a delimiter to parse configuration keys. |
|
58 | - * |
|
59 | - * @param array|string $config Array with settings or filename for the |
|
60 | - * settings file. |
|
61 | - * @param Schema|null $schema Optional. Config that contains default |
|
62 | - * values that can get overwritten. |
|
63 | - * @param Validator|null $validator Optional. Validator class that does the |
|
64 | - * actual validation. |
|
65 | - * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse |
|
66 | - * configuration keys. Defaults to "\", "/" & ".". |
|
67 | - * |
|
68 | - * @throws InvalidArgumentException If the config source is not a string or |
|
69 | - * array. |
|
70 | - * @throws RuntimeException If loading of the config source failed. |
|
71 | - * @throws UnexpectedValueException If the config file is not valid. |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - $config, |
|
75 | - Schema $schema = null, |
|
76 | - Validator $validator = null, |
|
77 | - $delimiter = null |
|
78 | - ) { |
|
79 | - $this->schema = $schema; |
|
80 | - $this->validator = $validator; |
|
50 | + /** |
|
51 | + * Instantiate the Config object. |
|
52 | + * |
|
53 | + * It accepts either an array with the configuration settings, or a |
|
54 | + * filename pointing to a PHP file it can include. |
|
55 | + * |
|
56 | + * @since 0.1.0 |
|
57 | + * @since 0.1.6 Accepts a delimiter to parse configuration keys. |
|
58 | + * |
|
59 | + * @param array|string $config Array with settings or filename for the |
|
60 | + * settings file. |
|
61 | + * @param Schema|null $schema Optional. Config that contains default |
|
62 | + * values that can get overwritten. |
|
63 | + * @param Validator|null $validator Optional. Validator class that does the |
|
64 | + * actual validation. |
|
65 | + * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse |
|
66 | + * configuration keys. Defaults to "\", "/" & ".". |
|
67 | + * |
|
68 | + * @throws InvalidArgumentException If the config source is not a string or |
|
69 | + * array. |
|
70 | + * @throws RuntimeException If loading of the config source failed. |
|
71 | + * @throws UnexpectedValueException If the config file is not valid. |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + $config, |
|
75 | + Schema $schema = null, |
|
76 | + Validator $validator = null, |
|
77 | + $delimiter = null |
|
78 | + ) { |
|
79 | + $this->schema = $schema; |
|
80 | + $this->validator = $validator; |
|
81 | 81 | |
82 | - // Make sure $config is either a string or array. |
|
83 | - if (! (is_string($config) || is_array($config))) { |
|
84 | - throw new InvalidArgumentException( |
|
85 | - sprintf( |
|
86 | - _('Invalid configuration source: %1$s'), |
|
87 | - print_r($config, true) |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
82 | + // Make sure $config is either a string or array. |
|
83 | + if (! (is_string($config) || is_array($config))) { |
|
84 | + throw new InvalidArgumentException( |
|
85 | + sprintf( |
|
86 | + _('Invalid configuration source: %1$s'), |
|
87 | + print_r($config, true) |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | |
92 | - if (is_string($config)) { |
|
93 | - $config = $this->fetchArrayData($config); |
|
94 | - } |
|
92 | + if (is_string($config)) { |
|
93 | + $config = $this->fetchArrayData($config); |
|
94 | + } |
|
95 | 95 | |
96 | - // Run the $config through the OptionsResolver. |
|
97 | - Assert\that($config)->isArray(); |
|
98 | - $config = $this->resolveOptions($config); |
|
96 | + // Run the $config through the OptionsResolver. |
|
97 | + Assert\that($config)->isArray(); |
|
98 | + $config = $this->resolveOptions($config); |
|
99 | 99 | |
100 | - // Instantiate the parent class. |
|
101 | - try { |
|
102 | - parent::__construct($config, $delimiter); |
|
103 | - } catch (Exception $exception) { |
|
104 | - throw new RuntimeException( |
|
105 | - sprintf( |
|
106 | - _('Could not instantiate the configuration through its parent. Reason: %1$s'), |
|
107 | - $exception->getMessage() |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
100 | + // Instantiate the parent class. |
|
101 | + try { |
|
102 | + parent::__construct($config, $delimiter); |
|
103 | + } catch (Exception $exception) { |
|
104 | + throw new RuntimeException( |
|
105 | + sprintf( |
|
106 | + _('Could not instantiate the configuration through its parent. Reason: %1$s'), |
|
107 | + $exception->getMessage() |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | 111 | |
112 | - // Finally, validate the resulting config. |
|
113 | - if (! $this->isValid()) { |
|
114 | - throw new UnexpectedValueException( |
|
115 | - sprintf( |
|
116 | - _('ConfigInterface file is not valid: %1$s'), |
|
117 | - print_r($config, true) |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - } |
|
112 | + // Finally, validate the resulting config. |
|
113 | + if (! $this->isValid()) { |
|
114 | + throw new UnexpectedValueException( |
|
115 | + sprintf( |
|
116 | + _('ConfigInterface file is not valid: %1$s'), |
|
117 | + print_r($config, true) |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Validate the Config file. |
|
125 | - * |
|
126 | - * @since 0.1.0 |
|
127 | - * |
|
128 | - * @return boolean |
|
129 | - */ |
|
130 | - public function isValid() |
|
131 | - { |
|
132 | - if ($this->validator) { |
|
133 | - return $this->validator->isValid($this); |
|
134 | - } |
|
123 | + /** |
|
124 | + * Validate the Config file. |
|
125 | + * |
|
126 | + * @since 0.1.0 |
|
127 | + * |
|
128 | + * @return boolean |
|
129 | + */ |
|
130 | + public function isValid() |
|
131 | + { |
|
132 | + if ($this->validator) { |
|
133 | + return $this->validator->isValid($this); |
|
134 | + } |
|
135 | 135 | |
136 | - return true; |
|
137 | - } |
|
136 | + return true; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Fetch array data from a string pointing to a file. |
|
141 | - * |
|
142 | - * @since 0.1.0 |
|
143 | - * |
|
144 | - * @param string $filename Filename for the settings file. |
|
145 | - * |
|
146 | - * @return array Array with configuration settings. |
|
147 | - * @throws RuntimeException If the config source is a non-existing |
|
148 | - * file. |
|
149 | - * @throws RuntimeException If loading of the config source failed. |
|
150 | - */ |
|
151 | - protected function fetchArrayData($filename) |
|
152 | - { |
|
153 | - try { |
|
154 | - // Assert that $filename is a readable file. |
|
155 | - Assert\that($filename) |
|
156 | - ->notEmpty() |
|
157 | - ->file() |
|
158 | - ->readable(); |
|
139 | + /** |
|
140 | + * Fetch array data from a string pointing to a file. |
|
141 | + * |
|
142 | + * @since 0.1.0 |
|
143 | + * |
|
144 | + * @param string $filename Filename for the settings file. |
|
145 | + * |
|
146 | + * @return array Array with configuration settings. |
|
147 | + * @throws RuntimeException If the config source is a non-existing |
|
148 | + * file. |
|
149 | + * @throws RuntimeException If loading of the config source failed. |
|
150 | + */ |
|
151 | + protected function fetchArrayData($filename) |
|
152 | + { |
|
153 | + try { |
|
154 | + // Assert that $filename is a readable file. |
|
155 | + Assert\that($filename) |
|
156 | + ->notEmpty() |
|
157 | + ->file() |
|
158 | + ->readable(); |
|
159 | 159 | |
160 | - // Try to load the file through PHP's include(). |
|
161 | - // Make sure we don't accidentally create output. |
|
162 | - ob_get_contents(); |
|
163 | - $config = include($filename); |
|
164 | - ob_clean(); |
|
160 | + // Try to load the file through PHP's include(). |
|
161 | + // Make sure we don't accidentally create output. |
|
162 | + ob_get_contents(); |
|
163 | + $config = include($filename); |
|
164 | + ob_clean(); |
|
165 | 165 | |
166 | - // The included should return an array. |
|
167 | - Assert\that($config)->isArray(); |
|
168 | - } catch (Exception $exception) { |
|
169 | - throw new RuntimeException( |
|
170 | - sprintf( |
|
171 | - _('Loading from configuration source %1$s failed. Reason: %2$s'), |
|
172 | - (string)$filename, |
|
173 | - (string)$exception->getMessage() |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
166 | + // The included should return an array. |
|
167 | + Assert\that($config)->isArray(); |
|
168 | + } catch (Exception $exception) { |
|
169 | + throw new RuntimeException( |
|
170 | + sprintf( |
|
171 | + _('Loading from configuration source %1$s failed. Reason: %2$s'), |
|
172 | + (string)$filename, |
|
173 | + (string)$exception->getMessage() |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | 177 | |
178 | - return $config; |
|
179 | - } |
|
178 | + return $config; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Process the passed-in defaults and merge them with the new values, while |
|
183 | - * checking that all required options are set. |
|
184 | - * |
|
185 | - * @since 0.1.0 |
|
186 | - * |
|
187 | - * @param array $config Configuration settings to resolve. |
|
188 | - * |
|
189 | - * @return array Resolved configuration settings. |
|
190 | - * @throws UnexpectedValueException If there are errors while resolving the |
|
191 | - * options. |
|
192 | - */ |
|
193 | - protected function resolveOptions($config) |
|
194 | - { |
|
195 | - if (! $this->schema) { |
|
196 | - return $config; |
|
197 | - } |
|
181 | + /** |
|
182 | + * Process the passed-in defaults and merge them with the new values, while |
|
183 | + * checking that all required options are set. |
|
184 | + * |
|
185 | + * @since 0.1.0 |
|
186 | + * |
|
187 | + * @param array $config Configuration settings to resolve. |
|
188 | + * |
|
189 | + * @return array Resolved configuration settings. |
|
190 | + * @throws UnexpectedValueException If there are errors while resolving the |
|
191 | + * options. |
|
192 | + */ |
|
193 | + protected function resolveOptions($config) |
|
194 | + { |
|
195 | + if (! $this->schema) { |
|
196 | + return $config; |
|
197 | + } |
|
198 | 198 | |
199 | - try { |
|
200 | - $resolver = new OptionsResolver(); |
|
201 | - if ($this->configureOptions($resolver)) { |
|
202 | - $config = $resolver->resolve($config); |
|
203 | - } |
|
204 | - } catch (Exception $exception) { |
|
205 | - throw new UnexpectedValueException( |
|
206 | - sprintf( |
|
207 | - _('Error while resolving config options: %1$s'), |
|
208 | - $exception->getMessage() |
|
209 | - ) |
|
210 | - ); |
|
211 | - } |
|
199 | + try { |
|
200 | + $resolver = new OptionsResolver(); |
|
201 | + if ($this->configureOptions($resolver)) { |
|
202 | + $config = $resolver->resolve($config); |
|
203 | + } |
|
204 | + } catch (Exception $exception) { |
|
205 | + throw new UnexpectedValueException( |
|
206 | + sprintf( |
|
207 | + _('Error while resolving config options: %1$s'), |
|
208 | + $exception->getMessage() |
|
209 | + ) |
|
210 | + ); |
|
211 | + } |
|
212 | 212 | |
213 | - return $config; |
|
214 | - } |
|
213 | + return $config; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Configure the possible and required options for the Config. |
|
218 | - * |
|
219 | - * This should return a bool to let the resolve_options() know whether the |
|
220 | - * actual resolving needs to be done or not. |
|
221 | - * |
|
222 | - * @since 0.1.0 |
|
223 | - * |
|
224 | - * @param OptionsResolver $resolver Reference to the OptionsResolver |
|
225 | - * instance. |
|
226 | - * |
|
227 | - * @return bool Whether to do the resolving. |
|
228 | - * @throws UnexpectedValueException If there are errors while processing. |
|
229 | - */ |
|
230 | - protected function configureOptions(OptionsResolver $resolver) |
|
231 | - { |
|
232 | - $defined = $this->schema->getDefinedOptions(); |
|
233 | - $defaults = $this->schema->getDefaultOptions(); |
|
234 | - $required = $this->schema->getRequiredOptions(); |
|
216 | + /** |
|
217 | + * Configure the possible and required options for the Config. |
|
218 | + * |
|
219 | + * This should return a bool to let the resolve_options() know whether the |
|
220 | + * actual resolving needs to be done or not. |
|
221 | + * |
|
222 | + * @since 0.1.0 |
|
223 | + * |
|
224 | + * @param OptionsResolver $resolver Reference to the OptionsResolver |
|
225 | + * instance. |
|
226 | + * |
|
227 | + * @return bool Whether to do the resolving. |
|
228 | + * @throws UnexpectedValueException If there are errors while processing. |
|
229 | + */ |
|
230 | + protected function configureOptions(OptionsResolver $resolver) |
|
231 | + { |
|
232 | + $defined = $this->schema->getDefinedOptions(); |
|
233 | + $defaults = $this->schema->getDefaultOptions(); |
|
234 | + $required = $this->schema->getRequiredOptions(); |
|
235 | 235 | |
236 | - if (! $defined && ! $defaults && ! $required) { |
|
237 | - return false; |
|
238 | - } |
|
236 | + if (! $defined && ! $defaults && ! $required) { |
|
237 | + return false; |
|
238 | + } |
|
239 | 239 | |
240 | - try { |
|
241 | - if ($defined) { |
|
242 | - $resolver->setDefined($defined); |
|
243 | - } |
|
244 | - if ($defaults) { |
|
245 | - $resolver->setDefaults($defaults); |
|
246 | - } |
|
247 | - if ($required) { |
|
248 | - $resolver->setRequired($required); |
|
249 | - } |
|
250 | - } catch (Exception $exception) { |
|
251 | - throw new UnexpectedValueException( |
|
252 | - sprintf( |
|
253 | - _('Error while processing config options: %1$s'), |
|
254 | - $exception->getMessage() |
|
255 | - ) |
|
256 | - ); |
|
257 | - } |
|
240 | + try { |
|
241 | + if ($defined) { |
|
242 | + $resolver->setDefined($defined); |
|
243 | + } |
|
244 | + if ($defaults) { |
|
245 | + $resolver->setDefaults($defaults); |
|
246 | + } |
|
247 | + if ($required) { |
|
248 | + $resolver->setRequired($required); |
|
249 | + } |
|
250 | + } catch (Exception $exception) { |
|
251 | + throw new UnexpectedValueException( |
|
252 | + sprintf( |
|
253 | + _('Error while processing config options: %1$s'), |
|
254 | + $exception->getMessage() |
|
255 | + ) |
|
256 | + ); |
|
257 | + } |
|
258 | 258 | |
259 | - return true; |
|
260 | - } |
|
259 | + return true; |
|
260 | + } |
|
261 | 261 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -27,82 +27,82 @@ discard block |
||
27 | 27 | interface ConfigInterface extends IteratorAggregate, ArrayAccess, Serializable, Countable |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Creates a copy of the ArrayObject. |
|
32 | - * |
|
33 | - * Returns a copy of the array. When the ArrayObject refers to an object an |
|
34 | - * array of the public properties of that object will be returned. |
|
35 | - * This is implemented by \ArrayObject. |
|
36 | - * |
|
37 | - * @since 0.1.0 |
|
38 | - * |
|
39 | - * @return array Copy of the array. |
|
40 | - */ |
|
41 | - public function getArrayCopy(); |
|
30 | + /** |
|
31 | + * Creates a copy of the ArrayObject. |
|
32 | + * |
|
33 | + * Returns a copy of the array. When the ArrayObject refers to an object an |
|
34 | + * array of the public properties of that object will be returned. |
|
35 | + * This is implemented by \ArrayObject. |
|
36 | + * |
|
37 | + * @since 0.1.0 |
|
38 | + * |
|
39 | + * @return array Copy of the array. |
|
40 | + */ |
|
41 | + public function getArrayCopy(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Check whether the Config has a specific key. |
|
45 | - * |
|
46 | - * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
47 | - * |
|
48 | - * @since 0.1.0 |
|
49 | - * @since 0.1.4 Accepts list of keys. |
|
50 | - * |
|
51 | - * @param string $_ List of keys. |
|
52 | - * |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function hasKey($_); |
|
43 | + /** |
|
44 | + * Check whether the Config has a specific key. |
|
45 | + * |
|
46 | + * To check a value several levels deep, add the keys for each level as a comma-separated list. |
|
47 | + * |
|
48 | + * @since 0.1.0 |
|
49 | + * @since 0.1.4 Accepts list of keys. |
|
50 | + * |
|
51 | + * @param string $_ List of keys. |
|
52 | + * |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function hasKey($_); |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get the value of a specific key. |
|
59 | - * |
|
60 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
61 | - * |
|
62 | - * @since 0.1.0 |
|
63 | - * @since 0.1.4 Accepts list of keys. |
|
64 | - * |
|
65 | - * @param string $_ List of keys. |
|
66 | - * |
|
67 | - * @return mixed |
|
68 | - */ |
|
69 | - public function getKey($_); |
|
57 | + /** |
|
58 | + * Get the value of a specific key. |
|
59 | + * |
|
60 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
61 | + * |
|
62 | + * @since 0.1.0 |
|
63 | + * @since 0.1.4 Accepts list of keys. |
|
64 | + * |
|
65 | + * @param string $_ List of keys. |
|
66 | + * |
|
67 | + * @return mixed |
|
68 | + */ |
|
69 | + public function getKey($_); |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
73 | - * |
|
74 | - * @since 0.1.4 |
|
75 | - * |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getAll(); |
|
71 | + /** |
|
72 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
73 | + * |
|
74 | + * @since 0.1.4 |
|
75 | + * |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getAll(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get the an array with all the keys |
|
82 | - * |
|
83 | - * @since 0.1.0 |
|
84 | - * |
|
85 | - * @return mixed |
|
86 | - */ |
|
87 | - public function getKeys(); |
|
80 | + /** |
|
81 | + * Get the an array with all the keys |
|
82 | + * |
|
83 | + * @since 0.1.0 |
|
84 | + * |
|
85 | + * @return mixed |
|
86 | + */ |
|
87 | + public function getKeys(); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Is the Config valid? |
|
91 | - * |
|
92 | - * @since 0.1.0 |
|
93 | - * |
|
94 | - * @return boolean |
|
95 | - */ |
|
96 | - public function isValid(); |
|
89 | + /** |
|
90 | + * Is the Config valid? |
|
91 | + * |
|
92 | + * @since 0.1.0 |
|
93 | + * |
|
94 | + * @return boolean |
|
95 | + */ |
|
96 | + public function isValid(); |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get a new config at a specific sub-level. |
|
100 | - * |
|
101 | - * @since 0.1.13 |
|
102 | - * |
|
103 | - * @param string $_ List of keys. |
|
104 | - * |
|
105 | - * @return ConfigInterface |
|
106 | - */ |
|
107 | - public function getSubConfig($_); |
|
98 | + /** |
|
99 | + * Get a new config at a specific sub-level. |
|
100 | + * |
|
101 | + * @since 0.1.13 |
|
102 | + * |
|
103 | + * @param string $_ List of keys. |
|
104 | + * |
|
105 | + * @return ConfigInterface |
|
106 | + */ |
|
107 | + public function getSubConfig($_); |
|
108 | 108 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -22,84 +22,84 @@ discard block |
||
22 | 22 | abstract class AbstractConfigSchema implements ConfigSchemaInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * The defined values that are recognized. |
|
27 | - * |
|
28 | - * @var ConfigInterface |
|
29 | - */ |
|
30 | - protected $defined; |
|
25 | + /** |
|
26 | + * The defined values that are recognized. |
|
27 | + * |
|
28 | + * @var ConfigInterface |
|
29 | + */ |
|
30 | + protected $defined; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The default values that can be overwritten. |
|
34 | - * |
|
35 | - * @var ConfigInterface |
|
36 | - */ |
|
37 | - protected $defaults; |
|
32 | + /** |
|
33 | + * The default values that can be overwritten. |
|
34 | + * |
|
35 | + * @var ConfigInterface |
|
36 | + */ |
|
37 | + protected $defaults; |
|
38 | 38 | |
39 | - /** |
|
40 | - * The required values that need to be set. |
|
41 | - * |
|
42 | - * @var ConfigInterface |
|
43 | - */ |
|
44 | - protected $required; |
|
39 | + /** |
|
40 | + * The required values that need to be set. |
|
41 | + * |
|
42 | + * @var ConfigInterface |
|
43 | + */ |
|
44 | + protected $required; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the set of defined options. |
|
48 | - * |
|
49 | - * @since 0.1.0 |
|
50 | - * |
|
51 | - * @return array|null |
|
52 | - */ |
|
53 | - public function getDefinedOptions() |
|
54 | - { |
|
55 | - if (! $this->defined) { |
|
56 | - return null; |
|
57 | - } |
|
46 | + /** |
|
47 | + * Get the set of defined options. |
|
48 | + * |
|
49 | + * @since 0.1.0 |
|
50 | + * |
|
51 | + * @return array|null |
|
52 | + */ |
|
53 | + public function getDefinedOptions() |
|
54 | + { |
|
55 | + if (! $this->defined) { |
|
56 | + return null; |
|
57 | + } |
|
58 | 58 | |
59 | - if ($this->defined instanceof ConfigInterface) { |
|
60 | - return $this->defined->getArrayCopy(); |
|
61 | - } |
|
59 | + if ($this->defined instanceof ConfigInterface) { |
|
60 | + return $this->defined->getArrayCopy(); |
|
61 | + } |
|
62 | 62 | |
63 | - return (array)$this->defined; |
|
64 | - } |
|
63 | + return (array)$this->defined; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get the set of default options. |
|
68 | - * |
|
69 | - * @since 0.1.0 |
|
70 | - * |
|
71 | - * @return array|null |
|
72 | - */ |
|
73 | - public function getDefaultOptions() |
|
74 | - { |
|
75 | - if (! $this->defaults) { |
|
76 | - return null; |
|
77 | - } |
|
66 | + /** |
|
67 | + * Get the set of default options. |
|
68 | + * |
|
69 | + * @since 0.1.0 |
|
70 | + * |
|
71 | + * @return array|null |
|
72 | + */ |
|
73 | + public function getDefaultOptions() |
|
74 | + { |
|
75 | + if (! $this->defaults) { |
|
76 | + return null; |
|
77 | + } |
|
78 | 78 | |
79 | - if ($this->defaults instanceof ConfigInterface) { |
|
80 | - return $this->defaults->getArrayCopy(); |
|
81 | - } |
|
79 | + if ($this->defaults instanceof ConfigInterface) { |
|
80 | + return $this->defaults->getArrayCopy(); |
|
81 | + } |
|
82 | 82 | |
83 | - return (array)$this->defaults; |
|
84 | - } |
|
83 | + return (array)$this->defaults; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get the set of required options. |
|
88 | - * |
|
89 | - * @since 0.1.0 |
|
90 | - * |
|
91 | - * @return array|null |
|
92 | - */ |
|
93 | - public function getRequiredOptions() |
|
94 | - { |
|
95 | - if (! $this->required) { |
|
96 | - return null; |
|
97 | - } |
|
86 | + /** |
|
87 | + * Get the set of required options. |
|
88 | + * |
|
89 | + * @since 0.1.0 |
|
90 | + * |
|
91 | + * @return array|null |
|
92 | + */ |
|
93 | + public function getRequiredOptions() |
|
94 | + { |
|
95 | + if (! $this->required) { |
|
96 | + return null; |
|
97 | + } |
|
98 | 98 | |
99 | - if ($this->required instanceof ConfigInterface) { |
|
100 | - return $this->required->getArrayCopy(); |
|
101 | - } |
|
99 | + if ($this->required instanceof ConfigInterface) { |
|
100 | + return $this->required->getArrayCopy(); |
|
101 | + } |
|
102 | 102 | |
103 | - return (array)$this->required; |
|
104 | - } |
|
103 | + return (array)$this->required; |
|
104 | + } |
|
105 | 105 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -24,135 +24,135 @@ discard block |
||
24 | 24 | class ConfigSchema extends AbstractConfigSchema |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * The key that is used in the schema to define a default value. |
|
29 | - */ |
|
30 | - const DEFAULT_VALUE = 'default'; |
|
31 | - /** |
|
32 | - * The key that is used in the schema to define a required value. |
|
33 | - */ |
|
34 | - const REQUIRED_KEY = 'required'; |
|
27 | + /** |
|
28 | + * The key that is used in the schema to define a default value. |
|
29 | + */ |
|
30 | + const DEFAULT_VALUE = 'default'; |
|
31 | + /** |
|
32 | + * The key that is used in the schema to define a required value. |
|
33 | + */ |
|
34 | + const REQUIRED_KEY = 'required'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Instantiate a ConfigSchema object. |
|
38 | - * |
|
39 | - * @since 0.1.0 |
|
40 | - * |
|
41 | - * @param ConfigInterface|array $schema The schema to parse. |
|
42 | - * |
|
43 | - * @throws InvalidArgumentException |
|
44 | - */ |
|
45 | - public function __construct($schema) |
|
46 | - { |
|
47 | - if ($schema instanceof ConfigInterface) { |
|
48 | - $schema = $schema->getArrayCopy(); |
|
49 | - } |
|
36 | + /** |
|
37 | + * Instantiate a ConfigSchema object. |
|
38 | + * |
|
39 | + * @since 0.1.0 |
|
40 | + * |
|
41 | + * @param ConfigInterface|array $schema The schema to parse. |
|
42 | + * |
|
43 | + * @throws InvalidArgumentException |
|
44 | + */ |
|
45 | + public function __construct($schema) |
|
46 | + { |
|
47 | + if ($schema instanceof ConfigInterface) { |
|
48 | + $schema = $schema->getArrayCopy(); |
|
49 | + } |
|
50 | 50 | |
51 | - if (! is_array($schema)) { |
|
52 | - throw new InvalidArgumentException( |
|
53 | - sprintf( |
|
54 | - _('Invalid schema source: %1$s'), |
|
55 | - print_r($schema, true) |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
51 | + if (! is_array($schema)) { |
|
52 | + throw new InvalidArgumentException( |
|
53 | + sprintf( |
|
54 | + _('Invalid schema source: %1$s'), |
|
55 | + print_r($schema, true) |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - array_walk($schema, [$this, 'parseSchema']); |
|
61 | - } |
|
60 | + array_walk($schema, [$this, 'parseSchema']); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Parse a single provided schema entry. |
|
65 | - * |
|
66 | - * @since 0.1.0 |
|
67 | - * |
|
68 | - * @param mixed $data The data associated with the key. |
|
69 | - * @param string $key The key of the schema data. |
|
70 | - */ |
|
71 | - protected function parseSchema($data, $key) |
|
72 | - { |
|
73 | - $this->parseDefined($key); |
|
63 | + /** |
|
64 | + * Parse a single provided schema entry. |
|
65 | + * |
|
66 | + * @since 0.1.0 |
|
67 | + * |
|
68 | + * @param mixed $data The data associated with the key. |
|
69 | + * @param string $key The key of the schema data. |
|
70 | + */ |
|
71 | + protected function parseSchema($data, $key) |
|
72 | + { |
|
73 | + $this->parseDefined($key); |
|
74 | 74 | |
75 | - if (array_key_exists(self::REQUIRED_KEY, $data)) { |
|
76 | - $this->parseRequired( |
|
77 | - $key, |
|
78 | - $data[self::REQUIRED_KEY] |
|
79 | - ); |
|
80 | - } |
|
75 | + if (array_key_exists(self::REQUIRED_KEY, $data)) { |
|
76 | + $this->parseRequired( |
|
77 | + $key, |
|
78 | + $data[self::REQUIRED_KEY] |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | - if (array_key_exists(self::DEFAULT_VALUE, $data)) { |
|
83 | - $this->parseDefault( |
|
84 | - $key, |
|
85 | - $data[self::DEFAULT_VALUE] |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
82 | + if (array_key_exists(self::DEFAULT_VALUE, $data)) { |
|
83 | + $this->parseDefault( |
|
84 | + $key, |
|
85 | + $data[self::DEFAULT_VALUE] |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Parse the set of defined values. |
|
92 | - * |
|
93 | - * @since 0.1.0 |
|
94 | - * |
|
95 | - * @param string $key The key of the schema data. |
|
96 | - */ |
|
97 | - protected function parseDefined($key) |
|
98 | - { |
|
99 | - $this->defined[] = $key; |
|
100 | - } |
|
90 | + /** |
|
91 | + * Parse the set of defined values. |
|
92 | + * |
|
93 | + * @since 0.1.0 |
|
94 | + * |
|
95 | + * @param string $key The key of the schema data. |
|
96 | + */ |
|
97 | + protected function parseDefined($key) |
|
98 | + { |
|
99 | + $this->defined[] = $key; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Parse the set of required values. |
|
104 | - * |
|
105 | - * @since 0.1.0 |
|
106 | - * |
|
107 | - * @param string $key The key of the schema data. |
|
108 | - * @param mixed $data The data associated with the key. |
|
109 | - */ |
|
110 | - protected function parseRequired($key, $data) |
|
111 | - { |
|
112 | - if ($this->isTruthy($data)) { |
|
113 | - $this->required[] = $key; |
|
114 | - } |
|
115 | - } |
|
102 | + /** |
|
103 | + * Parse the set of required values. |
|
104 | + * |
|
105 | + * @since 0.1.0 |
|
106 | + * |
|
107 | + * @param string $key The key of the schema data. |
|
108 | + * @param mixed $data The data associated with the key. |
|
109 | + */ |
|
110 | + protected function parseRequired($key, $data) |
|
111 | + { |
|
112 | + if ($this->isTruthy($data)) { |
|
113 | + $this->required[] = $key; |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Parse the set of default values. |
|
119 | - * |
|
120 | - * @since 0.1.0 |
|
121 | - * |
|
122 | - * @param string $key The key of the schema data. |
|
123 | - * @param mixed $data The data associated with the key. |
|
124 | - */ |
|
125 | - protected function parseDefault($key, $data) |
|
126 | - { |
|
127 | - $this->defaults[$key] = $data; |
|
128 | - } |
|
117 | + /** |
|
118 | + * Parse the set of default values. |
|
119 | + * |
|
120 | + * @since 0.1.0 |
|
121 | + * |
|
122 | + * @param string $key The key of the schema data. |
|
123 | + * @param mixed $data The data associated with the key. |
|
124 | + */ |
|
125 | + protected function parseDefault($key, $data) |
|
126 | + { |
|
127 | + $this->defaults[$key] = $data; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Return a boolean true or false for an arbitrary set of data. Recognizes |
|
132 | - * several different string values that should be valued as true. |
|
133 | - * |
|
134 | - * @since 0.1.0 |
|
135 | - * |
|
136 | - * @param mixed $data The data to evaluate. |
|
137 | - * |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - protected function isTruthy($data) |
|
141 | - { |
|
142 | - $truthy_values = [ |
|
143 | - true, |
|
144 | - 1, |
|
145 | - 'true', |
|
146 | - 'True', |
|
147 | - 'TRUE', |
|
148 | - 'y', |
|
149 | - 'Y', |
|
150 | - 'yes', |
|
151 | - 'Yes', |
|
152 | - 'YES', |
|
153 | - '√', |
|
154 | - ]; |
|
130 | + /** |
|
131 | + * Return a boolean true or false for an arbitrary set of data. Recognizes |
|
132 | + * several different string values that should be valued as true. |
|
133 | + * |
|
134 | + * @since 0.1.0 |
|
135 | + * |
|
136 | + * @param mixed $data The data to evaluate. |
|
137 | + * |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + protected function isTruthy($data) |
|
141 | + { |
|
142 | + $truthy_values = [ |
|
143 | + true, |
|
144 | + 1, |
|
145 | + 'true', |
|
146 | + 'True', |
|
147 | + 'TRUE', |
|
148 | + 'y', |
|
149 | + 'Y', |
|
150 | + 'yes', |
|
151 | + 'Yes', |
|
152 | + 'YES', |
|
153 | + '√', |
|
154 | + ]; |
|
155 | 155 | |
156 | - return in_array($data, $truthy_values, true); |
|
157 | - } |
|
156 | + return in_array($data, $truthy_values, true); |
|
157 | + } |
|
158 | 158 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bright Nucleus Config Component. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Config |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * Bright Nucleus Config Component. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Config |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Config; |
13 | 13 | |
@@ -26,105 +26,105 @@ discard block |
||
26 | 26 | trait ConfigTrait |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Reference to the Config object. |
|
31 | - * |
|
32 | - * @since 0.1.2 |
|
33 | - * |
|
34 | - * @var ConfigInterface |
|
35 | - */ |
|
36 | - protected $config; |
|
29 | + /** |
|
30 | + * Reference to the Config object. |
|
31 | + * |
|
32 | + * @since 0.1.2 |
|
33 | + * |
|
34 | + * @var ConfigInterface |
|
35 | + */ |
|
36 | + protected $config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Process the passed-in configuration file. |
|
40 | - * |
|
41 | - * @since 0.1.2 |
|
42 | - * |
|
43 | - * @param ConfigInterface $config The Config to process. |
|
44 | - * @param string ... List of keys. |
|
45 | - * |
|
46 | - * @throws RuntimeException If the arguments could not be parsed into a Config. |
|
47 | - */ |
|
48 | - protected function processConfig(ConfigInterface $config) |
|
49 | - { |
|
50 | - if (func_num_args() > 1) { |
|
51 | - try { |
|
52 | - $keys = func_get_args(); |
|
53 | - array_shift($keys); |
|
54 | - $config = $config->getSubConfig($keys); |
|
55 | - } catch (Exception $exception) { |
|
56 | - throw new RuntimeException( |
|
57 | - sprintf( |
|
58 | - _('Could not process the config with the arguments "%1$s".'), |
|
59 | - print_r(func_get_args(), true) |
|
60 | - ) |
|
61 | - ); |
|
62 | - } |
|
63 | - } |
|
64 | - $this->config = $config; |
|
65 | - } |
|
38 | + /** |
|
39 | + * Process the passed-in configuration file. |
|
40 | + * |
|
41 | + * @since 0.1.2 |
|
42 | + * |
|
43 | + * @param ConfigInterface $config The Config to process. |
|
44 | + * @param string ... List of keys. |
|
45 | + * |
|
46 | + * @throws RuntimeException If the arguments could not be parsed into a Config. |
|
47 | + */ |
|
48 | + protected function processConfig(ConfigInterface $config) |
|
49 | + { |
|
50 | + if (func_num_args() > 1) { |
|
51 | + try { |
|
52 | + $keys = func_get_args(); |
|
53 | + array_shift($keys); |
|
54 | + $config = $config->getSubConfig($keys); |
|
55 | + } catch (Exception $exception) { |
|
56 | + throw new RuntimeException( |
|
57 | + sprintf( |
|
58 | + _('Could not process the config with the arguments "%1$s".'), |
|
59 | + print_r(func_get_args(), true) |
|
60 | + ) |
|
61 | + ); |
|
62 | + } |
|
63 | + } |
|
64 | + $this->config = $config; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Check whether the Config has a specific key. |
|
69 | - * |
|
70 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
71 | - * |
|
72 | - * @since 0.1.2 |
|
73 | - * @since 0.1.5 Accepts list of keys. |
|
74 | - * |
|
75 | - * @param string|array $_ List of keys. |
|
76 | - * |
|
77 | - * @return bool Whether the key is known. |
|
78 | - */ |
|
79 | - protected function hasConfigKey($_) |
|
80 | - { |
|
81 | - $keys = func_get_args(); |
|
82 | - Assert\that($keys)->all()->string()->notEmpty(); |
|
67 | + /** |
|
68 | + * Check whether the Config has a specific key. |
|
69 | + * |
|
70 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
71 | + * |
|
72 | + * @since 0.1.2 |
|
73 | + * @since 0.1.5 Accepts list of keys. |
|
74 | + * |
|
75 | + * @param string|array $_ List of keys. |
|
76 | + * |
|
77 | + * @return bool Whether the key is known. |
|
78 | + */ |
|
79 | + protected function hasConfigKey($_) |
|
80 | + { |
|
81 | + $keys = func_get_args(); |
|
82 | + Assert\that($keys)->all()->string()->notEmpty(); |
|
83 | 83 | |
84 | - return $this->config->hasKey($keys); |
|
85 | - } |
|
84 | + return $this->config->hasKey($keys); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Get the Config value for a specific key. |
|
89 | - * |
|
90 | - * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
91 | - * |
|
92 | - * @since 0.1.2 |
|
93 | - * @since 0.1.5 Accepts list of keys. |
|
94 | - * |
|
95 | - * @param string|array $_ List of keys. |
|
96 | - * |
|
97 | - * @return mixed Value of the key. |
|
98 | - */ |
|
99 | - protected function getConfigKey($_) |
|
100 | - { |
|
101 | - $keys = func_get_args(); |
|
102 | - Assert\that($keys)->all()->string()->notEmpty(); |
|
87 | + /** |
|
88 | + * Get the Config value for a specific key. |
|
89 | + * |
|
90 | + * To get a value several levels deep, add the keys for each level as a comma-separated list. |
|
91 | + * |
|
92 | + * @since 0.1.2 |
|
93 | + * @since 0.1.5 Accepts list of keys. |
|
94 | + * |
|
95 | + * @param string|array $_ List of keys. |
|
96 | + * |
|
97 | + * @return mixed Value of the key. |
|
98 | + */ |
|
99 | + protected function getConfigKey($_) |
|
100 | + { |
|
101 | + $keys = func_get_args(); |
|
102 | + Assert\that($keys)->all()->string()->notEmpty(); |
|
103 | 103 | |
104 | - return $this->config->getKey($keys); |
|
105 | - } |
|
104 | + return $this->config->getKey($keys); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Get a (multi-dimensional) array of all the configuration settings. |
|
109 | - * |
|
110 | - * @since 0.1.4 |
|
111 | - * |
|
112 | - * @return array All the configuration settings. |
|
113 | - */ |
|
114 | - protected function getConfigArray() |
|
115 | - { |
|
116 | - return $this->config->getAll(); |
|
117 | - } |
|
107 | + /** |
|
108 | + * Get a (multi-dimensional) array of all the configuration settings. |
|
109 | + * |
|
110 | + * @since 0.1.4 |
|
111 | + * |
|
112 | + * @return array All the configuration settings. |
|
113 | + */ |
|
114 | + protected function getConfigArray() |
|
115 | + { |
|
116 | + return $this->config->getAll(); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Get an array of all the keys that are known by the Config. |
|
121 | - * |
|
122 | - * @since 0.1.2 |
|
123 | - * |
|
124 | - * @return array Array of strings containing all the keys. |
|
125 | - */ |
|
126 | - protected function getConfigKeys() |
|
127 | - { |
|
128 | - return $this->config->getKeys(); |
|
129 | - } |
|
119 | + /** |
|
120 | + * Get an array of all the keys that are known by the Config. |
|
121 | + * |
|
122 | + * @since 0.1.2 |
|
123 | + * |
|
124 | + * @return array Array of strings containing all the keys. |
|
125 | + */ |
|
126 | + protected function getConfigKeys() |
|
127 | + { |
|
128 | + return $this->config->getKeys(); |
|
129 | + } |
|
130 | 130 | } |