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