@@ -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,133 +24,133 @@ 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 | - * @throws InvalidArgumentException |
|
43 | - */ |
|
44 | - public function __construct($schema) |
|
45 | - { |
|
46 | - if ($schema instanceof ConfigInterface) { |
|
47 | - $schema = $schema->getArrayCopy(); |
|
48 | - } |
|
36 | + /** |
|
37 | + * Instantiate a ConfigSchema object. |
|
38 | + * |
|
39 | + * @since 0.1.0 |
|
40 | + * |
|
41 | + * @param ConfigInterface|array $schema The schema to parse. |
|
42 | + * @throws InvalidArgumentException |
|
43 | + */ |
|
44 | + public function __construct($schema) |
|
45 | + { |
|
46 | + if ($schema instanceof ConfigInterface) { |
|
47 | + $schema = $schema->getArrayCopy(); |
|
48 | + } |
|
49 | 49 | |
50 | - if (! is_array($schema)) { |
|
51 | - throw new InvalidArgumentException( |
|
52 | - sprintf( |
|
53 | - _('Invalid schema source: %1$s'), |
|
54 | - print_r($schema, true) |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
50 | + if (! is_array($schema)) { |
|
51 | + throw new InvalidArgumentException( |
|
52 | + sprintf( |
|
53 | + _('Invalid schema source: %1$s'), |
|
54 | + print_r($schema, true) |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - array_walk($schema, [$this, 'parseSchema']); |
|
60 | - } |
|
59 | + array_walk($schema, [$this, 'parseSchema']); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Parse a single provided schema entry. |
|
64 | - * |
|
65 | - * @since 0.1.0 |
|
66 | - * |
|
67 | - * @param mixed $data The data associated with the key. |
|
68 | - * @param string $key The key of the schema data. |
|
69 | - */ |
|
70 | - protected function parseSchema($data, $key) |
|
71 | - { |
|
72 | - $this->parseDefined($key); |
|
62 | + /** |
|
63 | + * Parse a single provided schema entry. |
|
64 | + * |
|
65 | + * @since 0.1.0 |
|
66 | + * |
|
67 | + * @param mixed $data The data associated with the key. |
|
68 | + * @param string $key The key of the schema data. |
|
69 | + */ |
|
70 | + protected function parseSchema($data, $key) |
|
71 | + { |
|
72 | + $this->parseDefined($key); |
|
73 | 73 | |
74 | - if (array_key_exists(self::REQUIRED_KEY, $data)) { |
|
75 | - $this->parseRequired( |
|
76 | - $key, |
|
77 | - $data[self::REQUIRED_KEY] |
|
78 | - ); |
|
79 | - } |
|
74 | + if (array_key_exists(self::REQUIRED_KEY, $data)) { |
|
75 | + $this->parseRequired( |
|
76 | + $key, |
|
77 | + $data[self::REQUIRED_KEY] |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - if (array_key_exists(self::DEFAULT_VALUE, $data)) { |
|
82 | - $this->parseDefault( |
|
83 | - $key, |
|
84 | - $data[self::DEFAULT_VALUE] |
|
85 | - ); |
|
86 | - } |
|
87 | - } |
|
81 | + if (array_key_exists(self::DEFAULT_VALUE, $data)) { |
|
82 | + $this->parseDefault( |
|
83 | + $key, |
|
84 | + $data[self::DEFAULT_VALUE] |
|
85 | + ); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Parse the set of defined values. |
|
91 | - * |
|
92 | - * @since 0.1.0 |
|
93 | - * |
|
94 | - * @param string $key The key of the schema data. |
|
95 | - */ |
|
96 | - protected function parseDefined($key) |
|
97 | - { |
|
98 | - $this->defined[] = $key; |
|
99 | - } |
|
89 | + /** |
|
90 | + * Parse the set of defined values. |
|
91 | + * |
|
92 | + * @since 0.1.0 |
|
93 | + * |
|
94 | + * @param string $key The key of the schema data. |
|
95 | + */ |
|
96 | + protected function parseDefined($key) |
|
97 | + { |
|
98 | + $this->defined[] = $key; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Parse the set of required values. |
|
103 | - * |
|
104 | - * @since 0.1.0 |
|
105 | - * |
|
106 | - * @param string $key The key of the schema data. |
|
107 | - * @param mixed $data The data associated with the key. |
|
108 | - */ |
|
109 | - protected function parseRequired($key, $data) |
|
110 | - { |
|
111 | - if ($this->isTruthy($data)) { |
|
112 | - $this->required[] = $key; |
|
113 | - } |
|
114 | - } |
|
101 | + /** |
|
102 | + * Parse the set of required values. |
|
103 | + * |
|
104 | + * @since 0.1.0 |
|
105 | + * |
|
106 | + * @param string $key The key of the schema data. |
|
107 | + * @param mixed $data The data associated with the key. |
|
108 | + */ |
|
109 | + protected function parseRequired($key, $data) |
|
110 | + { |
|
111 | + if ($this->isTruthy($data)) { |
|
112 | + $this->required[] = $key; |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Parse the set of default values. |
|
118 | - * |
|
119 | - * @since 0.1.0 |
|
120 | - * |
|
121 | - * @param string $key The key of the schema data. |
|
122 | - * @param mixed $data The data associated with the key. |
|
123 | - */ |
|
124 | - protected function parseDefault($key, $data) |
|
125 | - { |
|
126 | - $this->defaults[$key] = $data; |
|
127 | - } |
|
116 | + /** |
|
117 | + * Parse the set of default values. |
|
118 | + * |
|
119 | + * @since 0.1.0 |
|
120 | + * |
|
121 | + * @param string $key The key of the schema data. |
|
122 | + * @param mixed $data The data associated with the key. |
|
123 | + */ |
|
124 | + protected function parseDefault($key, $data) |
|
125 | + { |
|
126 | + $this->defaults[$key] = $data; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Return a boolean true or false for an arbitrary set of data. Recognizes |
|
131 | - * several different string values that should be valued as true. |
|
132 | - * |
|
133 | - * @since 0.1.0 |
|
134 | - * |
|
135 | - * @param mixed $data The data to evaluate. |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - protected function isTruthy($data) |
|
139 | - { |
|
140 | - $truthy_values = [ |
|
141 | - true, |
|
142 | - 1, |
|
143 | - 'true', |
|
144 | - 'True', |
|
145 | - 'TRUE', |
|
146 | - 'y', |
|
147 | - 'Y', |
|
148 | - 'yes', |
|
149 | - 'Yes', |
|
150 | - 'YES', |
|
151 | - '√', |
|
152 | - ]; |
|
129 | + /** |
|
130 | + * Return a boolean true or false for an arbitrary set of data. Recognizes |
|
131 | + * several different string values that should be valued as true. |
|
132 | + * |
|
133 | + * @since 0.1.0 |
|
134 | + * |
|
135 | + * @param mixed $data The data to evaluate. |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + protected function isTruthy($data) |
|
139 | + { |
|
140 | + $truthy_values = [ |
|
141 | + true, |
|
142 | + 1, |
|
143 | + 'true', |
|
144 | + 'True', |
|
145 | + 'TRUE', |
|
146 | + 'y', |
|
147 | + 'Y', |
|
148 | + 'yes', |
|
149 | + 'Yes', |
|
150 | + 'YES', |
|
151 | + '√', |
|
152 | + ]; |
|
153 | 153 | |
154 | - return in_array($data, $truthy_values, true); |
|
155 | - } |
|
154 | + return in_array($data, $truthy_values, true); |
|
155 | + } |
|
156 | 156 | } |