Passed
Push — master ( 447031...6e31ab )
by Alain
02:49
created
src/AbstractConfig.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -27,167 +27,167 @@
 block discarded – undo
27 27
 abstract class AbstractConfig extends ArrayObject implements ConfigInterface
28 28
 {
29 29
 
30
-    /**
31
-     * Array of strings that are used as delimiters to parse configuration keys.
32
-     *
33
-     * @since 0.1.6
34
-     *
35
-     * @var array
36
-     */
37
-    protected $delimiter = ['\\', '/', '.'];
38
-
39
-    /**
40
-     * Instantiate the AbstractConfig object.
41
-     *
42
-     * @since 0.1.0
43
-     * @since 0.1.6 Accepts a delimiter to parse configuration keys.
44
-     *
45
-     * @param array                $config    Array with settings.
46
-     * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
47
-     *                                        configuration keys. Defaults to "\", "/" & ".".
48
-     */
49
-    public function __construct(array $config, $delimiter = null)
50
-    {
51
-        // Make sure the config entries can be accessed as properties.
52
-        parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
53
-
54
-        if (null !== $delimiter) {
55
-            $this->delimiter = (array)$delimiter;
56
-        }
57
-    }
58
-
59
-    /**
60
-     * Check whether the Config has a specific key.
61
-     *
62
-     * To check a value several levels deep, add the keys for each level as a comma-separated list.
63
-     *
64
-     * @since 0.1.0
65
-     * @since 0.1.4 Accepts list of keys.
66
-     *
67
-     * @param string ... List of keys.
68
-     * @return bool
69
-     * @throws BadMethodCallException If no argument was provided.
70
-     */
71
-    public function hasKey()
72
-    {
73
-        $keys = array_reverse($this->getKeyArguments(func_get_args()));
74
-
75
-        $array = $this->getArrayCopy();
76
-        while (count($keys) > 0) {
77
-            $key = array_pop($keys);
78
-            if ( ! array_key_exists($key, $array)) {
79
-                return false;
80
-            }
81
-            $array = $array[$key];
82
-        }
83
-
84
-        return true;
85
-    }
86
-
87
-    /**
88
-     * Get the value of 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.0
93
-     * @since 0.1.4 Accepts list of keys.
94
-     *
95
-     * @param string ... List of keys.
96
-     * @return mixed
97
-     * @throws BadMethodCallException If no argument was provided.
98
-     * @throws OutOfRangeException If an unknown key is requested.
99
-     */
100
-    public function getKey()
101
-    {
102
-        $keys = $this->getKeyArguments(func_get_args());
103
-
104
-        if ( ! $this->hasKey($keys)) {
105
-            throw new OutOfRangeException(sprintf(_('The configuration key %1$s does not exist.'),
106
-                implode('->', $keys)));
107
-        }
108
-
109
-        $keys  = array_reverse($keys);
110
-        $array = $this->getArrayCopy();
111
-        while (count($keys) > 0) {
112
-            $key   = array_pop($keys);
113
-            $array = $array[$key];
114
-        }
115
-
116
-        return $array;
117
-    }
118
-
119
-    /**
120
-     * Get a (multi-dimensional) array of all the configuration settings.
121
-     *
122
-     * @since 0.1.4
123
-     *
124
-     * @return array
125
-     */
126
-    public function getAll()
127
-    {
128
-        return $this->getArrayCopy();
129
-    }
130
-
131
-    /**
132
-     * Get the an array with all the keys
133
-     *
134
-     * @since 0.1.0
135
-     * @return array
136
-     */
137
-    public function getKeys()
138
-    {
139
-        return array_keys((array)$this);
140
-    }
141
-
142
-    /**
143
-     * Extract the configuration key arguments from an arbitrary array.
144
-     *
145
-     * @since 0.1.6
146
-     *
147
-     * @param array $arguments Array as fetched through get_func_args().
148
-     * @return array Array of strings.
149
-     * @throws BadMethodCallException If no argument was provided.
150
-     */
151
-    protected function getKeyArguments($arguments)
152
-    {
153
-        if (count($arguments) < 1) {
154
-            throw new BadMethodCallException(_('No configuration key was provided.'));
155
-        }
156
-
157
-        $keys = [];
158
-        foreach ($arguments as $argument) {
159
-            if (is_array($argument)) {
160
-                $keys = array_merge($keys, $this->getKeyArguments($argument));
161
-            }
162
-            if (is_string($argument)) {
163
-                $keys = array_merge($keys, $this->parseKeysString($argument));
164
-            }
165
-        }
166
-
167
-        return $keys;
168
-    }
169
-
170
-    /**
171
-     * Extract individual keys from a delimited string.
172
-     *
173
-     * @since 0.1.6
174
-     *
175
-     * @param string $keyString Delimited string of keys.
176
-     * @return array Array of key strings.
177
-     */
178
-    protected function parseKeysString($keyString)
179
-    {
180
-        // Replace all of the configured delimiters by the first one, so that we can then use explode().
181
-        $normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString);
182
-
183
-        return (array)explode($this->delimiter[0], $normalizedString);
184
-    }
185
-
186
-    /**
187
-     * Validate the Config file.
188
-     *
189
-     * @since  0.1.0
190
-     * @return boolean
191
-     */
192
-    abstract public function isValid();
30
+	/**
31
+	 * Array of strings that are used as delimiters to parse configuration keys.
32
+	 *
33
+	 * @since 0.1.6
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $delimiter = ['\\', '/', '.'];
38
+
39
+	/**
40
+	 * Instantiate the AbstractConfig object.
41
+	 *
42
+	 * @since 0.1.0
43
+	 * @since 0.1.6 Accepts a delimiter to parse configuration keys.
44
+	 *
45
+	 * @param array                $config    Array with settings.
46
+	 * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
47
+	 *                                        configuration keys. Defaults to "\", "/" & ".".
48
+	 */
49
+	public function __construct(array $config, $delimiter = null)
50
+	{
51
+		// Make sure the config entries can be accessed as properties.
52
+		parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
53
+
54
+		if (null !== $delimiter) {
55
+			$this->delimiter = (array)$delimiter;
56
+		}
57
+	}
58
+
59
+	/**
60
+	 * Check whether the Config has a specific key.
61
+	 *
62
+	 * To check a value several levels deep, add the keys for each level as a comma-separated list.
63
+	 *
64
+	 * @since 0.1.0
65
+	 * @since 0.1.4 Accepts list of keys.
66
+	 *
67
+	 * @param string ... List of keys.
68
+	 * @return bool
69
+	 * @throws BadMethodCallException If no argument was provided.
70
+	 */
71
+	public function hasKey()
72
+	{
73
+		$keys = array_reverse($this->getKeyArguments(func_get_args()));
74
+
75
+		$array = $this->getArrayCopy();
76
+		while (count($keys) > 0) {
77
+			$key = array_pop($keys);
78
+			if ( ! array_key_exists($key, $array)) {
79
+				return false;
80
+			}
81
+			$array = $array[$key];
82
+		}
83
+
84
+		return true;
85
+	}
86
+
87
+	/**
88
+	 * Get the value of 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.0
93
+	 * @since 0.1.4 Accepts list of keys.
94
+	 *
95
+	 * @param string ... List of keys.
96
+	 * @return mixed
97
+	 * @throws BadMethodCallException If no argument was provided.
98
+	 * @throws OutOfRangeException If an unknown key is requested.
99
+	 */
100
+	public function getKey()
101
+	{
102
+		$keys = $this->getKeyArguments(func_get_args());
103
+
104
+		if ( ! $this->hasKey($keys)) {
105
+			throw new OutOfRangeException(sprintf(_('The configuration key %1$s does not exist.'),
106
+				implode('->', $keys)));
107
+		}
108
+
109
+		$keys  = array_reverse($keys);
110
+		$array = $this->getArrayCopy();
111
+		while (count($keys) > 0) {
112
+			$key   = array_pop($keys);
113
+			$array = $array[$key];
114
+		}
115
+
116
+		return $array;
117
+	}
118
+
119
+	/**
120
+	 * Get a (multi-dimensional) array of all the configuration settings.
121
+	 *
122
+	 * @since 0.1.4
123
+	 *
124
+	 * @return array
125
+	 */
126
+	public function getAll()
127
+	{
128
+		return $this->getArrayCopy();
129
+	}
130
+
131
+	/**
132
+	 * Get the an array with all the keys
133
+	 *
134
+	 * @since 0.1.0
135
+	 * @return array
136
+	 */
137
+	public function getKeys()
138
+	{
139
+		return array_keys((array)$this);
140
+	}
141
+
142
+	/**
143
+	 * Extract the configuration key arguments from an arbitrary array.
144
+	 *
145
+	 * @since 0.1.6
146
+	 *
147
+	 * @param array $arguments Array as fetched through get_func_args().
148
+	 * @return array Array of strings.
149
+	 * @throws BadMethodCallException If no argument was provided.
150
+	 */
151
+	protected function getKeyArguments($arguments)
152
+	{
153
+		if (count($arguments) < 1) {
154
+			throw new BadMethodCallException(_('No configuration key was provided.'));
155
+		}
156
+
157
+		$keys = [];
158
+		foreach ($arguments as $argument) {
159
+			if (is_array($argument)) {
160
+				$keys = array_merge($keys, $this->getKeyArguments($argument));
161
+			}
162
+			if (is_string($argument)) {
163
+				$keys = array_merge($keys, $this->parseKeysString($argument));
164
+			}
165
+		}
166
+
167
+		return $keys;
168
+	}
169
+
170
+	/**
171
+	 * Extract individual keys from a delimited string.
172
+	 *
173
+	 * @since 0.1.6
174
+	 *
175
+	 * @param string $keyString Delimited string of keys.
176
+	 * @return array Array of key strings.
177
+	 */
178
+	protected function parseKeysString($keyString)
179
+	{
180
+		// Replace all of the configured delimiters by the first one, so that we can then use explode().
181
+		$normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString);
182
+
183
+		return (array)explode($this->delimiter[0], $normalizedString);
184
+	}
185
+
186
+	/**
187
+	 * Validate the Config file.
188
+	 *
189
+	 * @since  0.1.0
190
+	 * @return boolean
191
+	 */
192
+	abstract public function isValid();
193 193
 }
Please login to merge, or discard this patch.
src/Config.php 1 patch
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
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
 
@@ -30,213 +30,213 @@  discard block
 block discarded – undo
30 30
 class Config extends AbstractConfig
31 31
 {
32 32
 
33
-    /**
34
-     * The schema of the Config file.
35
-     *
36
-     * @var Schema
37
-     */
38
-    protected $schema;
39
-
40
-    /**
41
-     * The Validator class that gets asked to do the validation of the config.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @var Validator
46
-     */
47
-    protected $validator;
48
-
49
-    /**
50
-     * Instantiate the Config object.
51
-     *
52
-     * It accepts either an array with the configuration settings, or a
53
-     * filename pointing to a PHP file it can include.
54
-     *
55
-     * @since 0.1.0
56
-     * @since 0.1.6 Accepts a delimiter to parse configuration keys.
57
-     *
58
-     * @param array|string         $config    Array with settings or filename for the
59
-     *                                        settings file.
60
-     * @param Schema|null          $schema    Optional. Config that contains default
61
-     *                                        values that can get overwritten.
62
-     * @param Validator|null       $validator Optional. Validator class that does the
63
-     *                                        actual validation.
64
-     * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
65
-     *                                        configuration keys. Defaults to "\", "/" & ".".
66
-     * @throws InvalidArgumentException If the config source is not a string or
67
-     *                                        array.
68
-     * @throws RuntimeException         If loading of the config source failed.
69
-     * @throws UnexpectedValueException If the config file is not valid.
70
-     */
71
-    public function __construct(
72
-        $config,
73
-        Schema $schema = null,
74
-        Validator $validator = null,
75
-        $delimiter = null
76
-    ) {
77
-        $this->schema    = $schema;
78
-        $this->validator = $validator;
79
-
80
-        // Make sure $config is either a string or array.
81
-        if ( ! (is_string($config) || is_array($config))) {
82
-            throw new InvalidArgumentException(sprintf(
83
-                _('Invalid configuration source: %1$s'),
84
-                print_r($config, true)
85
-            ));
86
-        }
87
-
88
-        if (is_string($config)) {
89
-            $config = $this->fetchArrayData($config);
90
-        }
91
-
92
-        $config = $this->resolveOptions($config);
93
-
94
-        parent::__construct($config, $delimiter);
95
-
96
-        // Finally, validate the resulting config.
97
-        if ( ! $this->isValid()) {
98
-            throw new UnexpectedValueException(sprintf(
99
-                _('ConfigInterface file is not valid: %1$s'),
100
-                print_r($config, true)
101
-            ));
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Fetch array data from a string pointing to a file.
107
-     *
108
-     * @since 0.1.0
109
-     *
110
-     * @param  string $config           Filename for the settings file.
111
-     * @return array                    Array with configuration settings.
112
-     * @throws RuntimeException         If the config source is a non-existing
113
-     *                                  file.
114
-     * @throws RuntimeException         If loading of the config source failed.
115
-     */
116
-    protected function fetchArrayData($config)
117
-    {
118
-        if (is_string($config) && ! ('' === $config)) {
119
-
120
-            // $config is a valid string, make sure it is an existing file.
121
-            if ( ! file_exists($config)) {
122
-                throw new RuntimeException(sprintf(
123
-                    _('Non-existing configuration source: %1$s'),
124
-                    (string)$config
125
-                ));
126
-            }
127
-
128
-            // Try to load the file through PHP's include().
129
-            $configString = $config;
130
-            try {
131
-                // Make sure we don't accidentally create output.
132
-                ob_get_contents();
133
-                $config = include($configString);
134
-                ob_clean();
135
-
136
-                // The included should return an array.
137
-                if ( ! is_array($config)) {
138
-                    throw new RuntimeException(_('File inclusion did not return an array.'));
139
-                }
140
-            } catch (Exception $exception) {
141
-                throw new RuntimeException(sprintf(
142
-                    _('Loading from configuration source %1$s failed. Reason: %2$s'),
143
-                    (string)$configString,
144
-                    (string)$exception->getMessage()
145
-                ));
146
-            }
147
-        }
148
-
149
-        return (array)$config;
150
-    }
151
-
152
-    /**
153
-     * Process the passed-in defaults and merge them with the new values, while
154
-     * checking that all required options are set.
155
-     *
156
-     * @since 0.1.0
157
-     *
158
-     * @param array $config             Configuration settings to resolve.
159
-     * @return array                    Resolved configuration settings.
160
-     * @throws UnexpectedValueException If there are errors while resolving the
161
-     *                                  options.
162
-     */
163
-    protected function resolveOptions($config)
164
-    {
165
-        if ( ! $this->schema) {
166
-            return $config;
167
-        }
168
-
169
-        try {
170
-            $resolver = new OptionsResolver();
171
-            if ($this->configureOptions($resolver)) {
172
-                $config = $resolver->resolve($config);
173
-            }
174
-        } catch (Exception $exception) {
175
-            throw new UnexpectedValueException(sprintf(
176
-                _('Error while resolving config options: %1$s'),
177
-                $exception->getMessage()
178
-            ));
179
-        }
180
-
181
-        return $config;
182
-    }
183
-
184
-    /**
185
-     * Configure the possible and required options for the Config.
186
-     *
187
-     * This should return a bool to let the resolve_options() know whether the
188
-     * actual resolving needs to be done or not.
189
-     *
190
-     * @since 0.1.0
191
-     *
192
-     * @param OptionsResolver $resolver Reference to the OptionsResolver
193
-     *                                  instance.
194
-     * @return bool Whether to do the resolving.
195
-     * @throws UnexpectedValueException If there are errors while processing.
196
-     */
197
-    protected function configureOptions(OptionsResolver $resolver)
198
-    {
199
-        $defined  = $this->schema->getDefinedOptions();
200
-        $defaults = $this->schema->getDefaultOptions();
201
-        $required = $this->schema->getRequiredOptions();
202
-
203
-        if ( ! $defined && ! $defaults && ! $required) {
204
-            return false;
205
-        }
206
-
207
-        try {
208
-            if ($defined) {
209
-                $resolver->setDefined($defined);
210
-            }
211
-            if ($defaults) {
212
-                $resolver->setDefaults($defaults);
213
-            }
214
-            if ($required) {
215
-                $resolver->setRequired($required);
216
-            }
217
-        } catch (Exception $exception) {
218
-            throw new UnexpectedValueException(sprintf(
219
-                _('Error while processing config options: %1$s'),
220
-                $exception->getMessage()
221
-            ));
222
-        }
223
-
224
-        return true;
225
-    }
226
-
227
-    /**
228
-     * Validate the Config file.
229
-     *
230
-     * @since  0.1.0
231
-     *
232
-     * @return boolean
233
-     */
234
-    public function isValid()
235
-    {
236
-        if ($this->validator) {
237
-            return $this->validator->isValid($this);
238
-        }
239
-
240
-        return true;
241
-    }
33
+	/**
34
+	 * The schema of the Config file.
35
+	 *
36
+	 * @var Schema
37
+	 */
38
+	protected $schema;
39
+
40
+	/**
41
+	 * The Validator class that gets asked to do the validation of the config.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @var Validator
46
+	 */
47
+	protected $validator;
48
+
49
+	/**
50
+	 * Instantiate the Config object.
51
+	 *
52
+	 * It accepts either an array with the configuration settings, or a
53
+	 * filename pointing to a PHP file it can include.
54
+	 *
55
+	 * @since 0.1.0
56
+	 * @since 0.1.6 Accepts a delimiter to parse configuration keys.
57
+	 *
58
+	 * @param array|string         $config    Array with settings or filename for the
59
+	 *                                        settings file.
60
+	 * @param Schema|null          $schema    Optional. Config that contains default
61
+	 *                                        values that can get overwritten.
62
+	 * @param Validator|null       $validator Optional. Validator class that does the
63
+	 *                                        actual validation.
64
+	 * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
65
+	 *                                        configuration keys. Defaults to "\", "/" & ".".
66
+	 * @throws InvalidArgumentException If the config source is not a string or
67
+	 *                                        array.
68
+	 * @throws RuntimeException         If loading of the config source failed.
69
+	 * @throws UnexpectedValueException If the config file is not valid.
70
+	 */
71
+	public function __construct(
72
+		$config,
73
+		Schema $schema = null,
74
+		Validator $validator = null,
75
+		$delimiter = null
76
+	) {
77
+		$this->schema    = $schema;
78
+		$this->validator = $validator;
79
+
80
+		// Make sure $config is either a string or array.
81
+		if ( ! (is_string($config) || is_array($config))) {
82
+			throw new InvalidArgumentException(sprintf(
83
+				_('Invalid configuration source: %1$s'),
84
+				print_r($config, true)
85
+			));
86
+		}
87
+
88
+		if (is_string($config)) {
89
+			$config = $this->fetchArrayData($config);
90
+		}
91
+
92
+		$config = $this->resolveOptions($config);
93
+
94
+		parent::__construct($config, $delimiter);
95
+
96
+		// Finally, validate the resulting config.
97
+		if ( ! $this->isValid()) {
98
+			throw new UnexpectedValueException(sprintf(
99
+				_('ConfigInterface file is not valid: %1$s'),
100
+				print_r($config, true)
101
+			));
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Fetch array data from a string pointing to a file.
107
+	 *
108
+	 * @since 0.1.0
109
+	 *
110
+	 * @param  string $config           Filename for the settings file.
111
+	 * @return array                    Array with configuration settings.
112
+	 * @throws RuntimeException         If the config source is a non-existing
113
+	 *                                  file.
114
+	 * @throws RuntimeException         If loading of the config source failed.
115
+	 */
116
+	protected function fetchArrayData($config)
117
+	{
118
+		if (is_string($config) && ! ('' === $config)) {
119
+
120
+			// $config is a valid string, make sure it is an existing file.
121
+			if ( ! file_exists($config)) {
122
+				throw new RuntimeException(sprintf(
123
+					_('Non-existing configuration source: %1$s'),
124
+					(string)$config
125
+				));
126
+			}
127
+
128
+			// Try to load the file through PHP's include().
129
+			$configString = $config;
130
+			try {
131
+				// Make sure we don't accidentally create output.
132
+				ob_get_contents();
133
+				$config = include($configString);
134
+				ob_clean();
135
+
136
+				// The included should return an array.
137
+				if ( ! is_array($config)) {
138
+					throw new RuntimeException(_('File inclusion did not return an array.'));
139
+				}
140
+			} catch (Exception $exception) {
141
+				throw new RuntimeException(sprintf(
142
+					_('Loading from configuration source %1$s failed. Reason: %2$s'),
143
+					(string)$configString,
144
+					(string)$exception->getMessage()
145
+				));
146
+			}
147
+		}
148
+
149
+		return (array)$config;
150
+	}
151
+
152
+	/**
153
+	 * Process the passed-in defaults and merge them with the new values, while
154
+	 * checking that all required options are set.
155
+	 *
156
+	 * @since 0.1.0
157
+	 *
158
+	 * @param array $config             Configuration settings to resolve.
159
+	 * @return array                    Resolved configuration settings.
160
+	 * @throws UnexpectedValueException If there are errors while resolving the
161
+	 *                                  options.
162
+	 */
163
+	protected function resolveOptions($config)
164
+	{
165
+		if ( ! $this->schema) {
166
+			return $config;
167
+		}
168
+
169
+		try {
170
+			$resolver = new OptionsResolver();
171
+			if ($this->configureOptions($resolver)) {
172
+				$config = $resolver->resolve($config);
173
+			}
174
+		} catch (Exception $exception) {
175
+			throw new UnexpectedValueException(sprintf(
176
+				_('Error while resolving config options: %1$s'),
177
+				$exception->getMessage()
178
+			));
179
+		}
180
+
181
+		return $config;
182
+	}
183
+
184
+	/**
185
+	 * Configure the possible and required options for the Config.
186
+	 *
187
+	 * This should return a bool to let the resolve_options() know whether the
188
+	 * actual resolving needs to be done or not.
189
+	 *
190
+	 * @since 0.1.0
191
+	 *
192
+	 * @param OptionsResolver $resolver Reference to the OptionsResolver
193
+	 *                                  instance.
194
+	 * @return bool Whether to do the resolving.
195
+	 * @throws UnexpectedValueException If there are errors while processing.
196
+	 */
197
+	protected function configureOptions(OptionsResolver $resolver)
198
+	{
199
+		$defined  = $this->schema->getDefinedOptions();
200
+		$defaults = $this->schema->getDefaultOptions();
201
+		$required = $this->schema->getRequiredOptions();
202
+
203
+		if ( ! $defined && ! $defaults && ! $required) {
204
+			return false;
205
+		}
206
+
207
+		try {
208
+			if ($defined) {
209
+				$resolver->setDefined($defined);
210
+			}
211
+			if ($defaults) {
212
+				$resolver->setDefaults($defaults);
213
+			}
214
+			if ($required) {
215
+				$resolver->setRequired($required);
216
+			}
217
+		} catch (Exception $exception) {
218
+			throw new UnexpectedValueException(sprintf(
219
+				_('Error while processing config options: %1$s'),
220
+				$exception->getMessage()
221
+			));
222
+		}
223
+
224
+		return true;
225
+	}
226
+
227
+	/**
228
+	 * Validate the Config file.
229
+	 *
230
+	 * @since  0.1.0
231
+	 *
232
+	 * @return boolean
233
+	 */
234
+	public function isValid()
235
+	{
236
+		if ($this->validator) {
237
+			return $this->validator->isValid($this);
238
+		}
239
+
240
+		return true;
241
+	}
242 242
 }
Please login to merge, or discard this patch.