Passed
Push — master ( 26d549...0e9514 )
by Alain
02:38
created
src/Loader/LoaderFactory.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -25,97 +25,97 @@
 block discarded – undo
25 25
 class LoaderFactory
26 26
 {
27 27
 
28
-    /**
29
-     * Array of fully qualified class names of known loaders.
30
-     *
31
-     * @var array<string>
32
-     *
33
-     * @since 0.4.0
34
-     */
35
-    protected static $loaders = [
36
-        'BrightNucleus\Config\Loader\PHPLoader',
37
-    ];
28
+	/**
29
+	 * Array of fully qualified class names of known loaders.
30
+	 *
31
+	 * @var array<string>
32
+	 *
33
+	 * @since 0.4.0
34
+	 */
35
+	protected static $loaders = [
36
+		'BrightNucleus\Config\Loader\PHPLoader',
37
+	];
38 38
 
39
-    /**
40
-     * Array of instantiated loaders.
41
-     *
42
-     * These are lazily instantiated and added as needed.
43
-     *
44
-     * @var LoaderInterface[]
45
-     *
46
-     * @since 0.4.0
47
-     */
48
-    protected static $loaderInstances = [];
39
+	/**
40
+	 * Array of instantiated loaders.
41
+	 *
42
+	 * These are lazily instantiated and added as needed.
43
+	 *
44
+	 * @var LoaderInterface[]
45
+	 *
46
+	 * @since 0.4.0
47
+	 */
48
+	protected static $loaderInstances = [];
49 49
 
50
-    /**
51
-     * Create a new Loader from an URI.
52
-     *
53
-     * @since 0.4.0
54
-     *
55
-     * @param string $uri URI of the resource to create a loader for.
56
-     *
57
-     * @return LoaderInterface Loader that is able to load the given URI.
58
-     * @throws FailedToLoadConfigException If no suitable loader was found.
59
-     */
60
-    public static function createFromUri($uri)
61
-    {
62
-        foreach (static::$loaders as $loader) {
63
-            if ($loader::canLoad($uri)) {
64
-                return static::getLoader($loader);
65
-            }
66
-        }
50
+	/**
51
+	 * Create a new Loader from an URI.
52
+	 *
53
+	 * @since 0.4.0
54
+	 *
55
+	 * @param string $uri URI of the resource to create a loader for.
56
+	 *
57
+	 * @return LoaderInterface Loader that is able to load the given URI.
58
+	 * @throws FailedToLoadConfigException If no suitable loader was found.
59
+	 */
60
+	public static function createFromUri($uri)
61
+	{
62
+		foreach (static::$loaders as $loader) {
63
+			if ($loader::canLoad($uri)) {
64
+				return static::getLoader($loader);
65
+			}
66
+		}
67 67
 
68
-        throw new FailedToLoadConfigException(
69
-            sprintf(
70
-                _('Could not find a suitable loader for URI "%1$s".'),
71
-                $uri
72
-            )
73
-        );
74
-    }
68
+		throw new FailedToLoadConfigException(
69
+			sprintf(
70
+				_('Could not find a suitable loader for URI "%1$s".'),
71
+				$uri
72
+			)
73
+		);
74
+	}
75 75
 
76
-    /**
77
-     * Get an instance of a specific loader.
78
-     *
79
-     * The loader is lazily instantiated if needed.
80
-     *
81
-     * @since 0.4.0
82
-     *
83
-     * @param string $loaderClass Fully qualified class name of the loader to get.
84
-     *
85
-     * @return LoaderInterface Instance of the requested loader.
86
-     * @throws FailedToLoadConfigException If the loader class could not be instantiated.
87
-     */
88
-    public static function getLoader($loaderClass)
89
-    {
90
-        try {
91
-            if (! array_key_exists($loaderClass, static::$loaderInstances)) {
92
-                static::$loaderInstances[$loaderClass] = new $loaderClass;
93
-            }
76
+	/**
77
+	 * Get an instance of a specific loader.
78
+	 *
79
+	 * The loader is lazily instantiated if needed.
80
+	 *
81
+	 * @since 0.4.0
82
+	 *
83
+	 * @param string $loaderClass Fully qualified class name of the loader to get.
84
+	 *
85
+	 * @return LoaderInterface Instance of the requested loader.
86
+	 * @throws FailedToLoadConfigException If the loader class could not be instantiated.
87
+	 */
88
+	public static function getLoader($loaderClass)
89
+	{
90
+		try {
91
+			if (! array_key_exists($loaderClass, static::$loaderInstances)) {
92
+				static::$loaderInstances[$loaderClass] = new $loaderClass;
93
+			}
94 94
 
95
-            return static::$loaderInstances[$loaderClass];
96
-        } catch (Exception $exception) {
97
-            throw new FailedToLoadConfigException(
98
-                sprintf(
99
-                    _('Could not instantiate the requested loader class "%1$s".'),
100
-                    $loaderClass
101
-                )
102
-            );
103
-        }
104
-    }
95
+			return static::$loaderInstances[$loaderClass];
96
+		} catch (Exception $exception) {
97
+			throw new FailedToLoadConfigException(
98
+				sprintf(
99
+					_('Could not instantiate the requested loader class "%1$s".'),
100
+					$loaderClass
101
+				)
102
+			);
103
+		}
104
+	}
105 105
 
106
-    /**
107
-     * Register a new loader.
108
-     *
109
-     * @since 0.4.0
110
-     *
111
-     * @param string $loader Fully qualified class name of a loader implementing LoaderInterface.
112
-     */
113
-    public static function registerLoader($loader)
114
-    {
115
-        if (in_array($loader, static::$loaders, true)) {
116
-            return;
117
-        }
106
+	/**
107
+	 * Register a new loader.
108
+	 *
109
+	 * @since 0.4.0
110
+	 *
111
+	 * @param string $loader Fully qualified class name of a loader implementing LoaderInterface.
112
+	 */
113
+	public static function registerLoader($loader)
114
+	{
115
+		if (in_array($loader, static::$loaders, true)) {
116
+			return;
117
+		}
118 118
 
119
-        static::$loaders [] = $loader;
120
-    }
119
+		static::$loaders [] = $loader;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
     public static function getLoader($loaderClass)
89 89
     {
90 90
         try {
91
-            if (! array_key_exists($loaderClass, static::$loaderInstances)) {
91
+            if ( ! array_key_exists($loaderClass, static::$loaderInstances)) {
92 92
                 static::$loaderInstances[$loaderClass] = new $loaderClass;
93 93
             }
94 94
 
Please login to merge, or discard this patch.
src/ConfigTrait.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -26,105 +26,105 @@
 block discarded – undo
26 26
 trait ConfigTrait
27 27
 {
28 28
 
29
-    /**
30
-     * Reference to the Config object.
31
-     *
32
-     * @since 0.1.2
33
-     *
34
-     * @var ConfigInterface
35
-     */
36
-    protected $config;
29
+	/**
30
+	 * Reference to the Config object.
31
+	 *
32
+	 * @since 0.1.2
33
+	 *
34
+	 * @var ConfigInterface
35
+	 */
36
+	protected $config;
37 37
 
38
-    /**
39
-     * Process the passed-in configuration file.
40
-     *
41
-     * @since 0.1.2
42
-     *
43
-     * @param ConfigInterface $config The Config to process.
44
-     * @param                 string  ... List of keys.
45
-     *
46
-     * @throws FailedToProcessConfigException If the arguments could not be parsed into a Config.
47
-     */
48
-    protected function processConfig(ConfigInterface $config)
49
-    {
50
-        if (func_num_args() > 1) {
51
-            try {
52
-                $keys = func_get_args();
53
-                array_shift($keys);
54
-                $config = $config->getSubConfig($keys);
55
-            } catch (Exception $exception) {
56
-                throw new FailedToProcessConfigException(
57
-                    sprintf(
58
-                        _('Could not process the config with the arguments "%1$s".'),
59
-                        print_r(func_get_args(), true)
60
-                    )
61
-                );
62
-            }
63
-        }
64
-        $this->config = $config;
65
-    }
38
+	/**
39
+	 * Process the passed-in configuration file.
40
+	 *
41
+	 * @since 0.1.2
42
+	 *
43
+	 * @param ConfigInterface $config The Config to process.
44
+	 * @param                 string  ... List of keys.
45
+	 *
46
+	 * @throws FailedToProcessConfigException If the arguments could not be parsed into a Config.
47
+	 */
48
+	protected function processConfig(ConfigInterface $config)
49
+	{
50
+		if (func_num_args() > 1) {
51
+			try {
52
+				$keys = func_get_args();
53
+				array_shift($keys);
54
+				$config = $config->getSubConfig($keys);
55
+			} catch (Exception $exception) {
56
+				throw new FailedToProcessConfigException(
57
+					sprintf(
58
+						_('Could not process the config with the arguments "%1$s".'),
59
+						print_r(func_get_args(), true)
60
+					)
61
+				);
62
+			}
63
+		}
64
+		$this->config = $config;
65
+	}
66 66
 
67
-    /**
68
-     * Check whether the Config has a specific key.
69
-     *
70
-     * To get a value several levels deep, add the keys for each level as a comma-separated list.
71
-     *
72
-     * @since 0.1.2
73
-     * @since 0.1.5 Accepts list of keys.
74
-     *
75
-     * @param string|array $_ List of keys.
76
-     *
77
-     * @return bool Whether the key is known.
78
-     */
79
-    protected function hasConfigKey($_)
80
-    {
81
-        $keys = func_get_args();
82
-        Assert\that($keys)->all()->string()->notEmpty();
67
+	/**
68
+	 * Check whether the Config has a specific key.
69
+	 *
70
+	 * To get a value several levels deep, add the keys for each level as a comma-separated list.
71
+	 *
72
+	 * @since 0.1.2
73
+	 * @since 0.1.5 Accepts list of keys.
74
+	 *
75
+	 * @param string|array $_ List of keys.
76
+	 *
77
+	 * @return bool Whether the key is known.
78
+	 */
79
+	protected function hasConfigKey($_)
80
+	{
81
+		$keys = func_get_args();
82
+		Assert\that($keys)->all()->string()->notEmpty();
83 83
 
84
-        return $this->config->hasKey($keys);
85
-    }
84
+		return $this->config->hasKey($keys);
85
+	}
86 86
 
87
-    /**
88
-     * Get the Config value for a specific key.
89
-     *
90
-     * To get a value several levels deep, add the keys for each level as a comma-separated list.
91
-     *
92
-     * @since 0.1.2
93
-     * @since 0.1.5 Accepts list of keys.
94
-     *
95
-     * @param string|array $_ List of keys.
96
-     *
97
-     * @return mixed Value of the key.
98
-     */
99
-    protected function getConfigKey($_)
100
-    {
101
-        $keys = func_get_args();
102
-        Assert\that($keys)->all()->string()->notEmpty();
87
+	/**
88
+	 * Get the Config value for a specific key.
89
+	 *
90
+	 * To get a value several levels deep, add the keys for each level as a comma-separated list.
91
+	 *
92
+	 * @since 0.1.2
93
+	 * @since 0.1.5 Accepts list of keys.
94
+	 *
95
+	 * @param string|array $_ List of keys.
96
+	 *
97
+	 * @return mixed Value of the key.
98
+	 */
99
+	protected function getConfigKey($_)
100
+	{
101
+		$keys = func_get_args();
102
+		Assert\that($keys)->all()->string()->notEmpty();
103 103
 
104
-        return $this->config->getKey($keys);
105
-    }
104
+		return $this->config->getKey($keys);
105
+	}
106 106
 
107
-    /**
108
-     * Get a (multi-dimensional) array of all the configuration settings.
109
-     *
110
-     * @since 0.1.4
111
-     *
112
-     * @return array All the configuration settings.
113
-     */
114
-    protected function getConfigArray()
115
-    {
116
-        return $this->config->getAll();
117
-    }
107
+	/**
108
+	 * Get a (multi-dimensional) array of all the configuration settings.
109
+	 *
110
+	 * @since 0.1.4
111
+	 *
112
+	 * @return array All the configuration settings.
113
+	 */
114
+	protected function getConfigArray()
115
+	{
116
+		return $this->config->getAll();
117
+	}
118 118
 
119
-    /**
120
-     * Get an array of all the keys that are known by the Config.
121
-     *
122
-     * @since 0.1.2
123
-     *
124
-     * @return array Array of strings containing all the keys.
125
-     */
126
-    protected function getConfigKeys()
127
-    {
128
-        return $this->config->getKeys();
129
-    }
119
+	/**
120
+	 * Get an array of all the keys that are known by the Config.
121
+	 *
122
+	 * @since 0.1.2
123
+	 *
124
+	 * @return array Array of strings containing all the keys.
125
+	 */
126
+	protected function getConfigKeys()
127
+	{
128
+		return $this->config->getKeys();
129
+	}
130 130
 }
Please login to merge, or discard this patch.
src/Loader.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -25,20 +25,20 @@
 block discarded – undo
25 25
 class Loader
26 26
 {
27 27
 
28
-    /**
29
-     * Static convenience function to load a configuration from an URI.
30
-     *
31
-     * @since 0.4.0
32
-     *
33
-     * @param string $uri URI of the resource to load.
34
-     *
35
-     * @return array|null Parsed data loaded from the resource.
36
-     * @throws FailedToLoadConfigException If the configuration could not be loaded.
37
-     */
38
-    public static function load($uri)
39
-    {
40
-        $loader = LoaderFactory::createFromUri($uri);
28
+	/**
29
+	 * Static convenience function to load a configuration from an URI.
30
+	 *
31
+	 * @since 0.4.0
32
+	 *
33
+	 * @param string $uri URI of the resource to load.
34
+	 *
35
+	 * @return array|null Parsed data loaded from the resource.
36
+	 * @throws FailedToLoadConfigException If the configuration could not be loaded.
37
+	 */
38
+	public static function load($uri)
39
+	{
40
+		$loader = LoaderFactory::createFromUri($uri);
41 41
 
42
-        return $loader->load($uri);
43
-    }
42
+		return $loader->load($uri);
43
+	}
44 44
 }
Please login to merge, or discard this patch.
src/Config.php 2 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -33,189 +33,189 @@
 block discarded – undo
33 33
 class Config extends AbstractConfig
34 34
 {
35 35
 
36
-    /**
37
-     * The schema of the Config file.
38
-     *
39
-     * @var Schema
40
-     */
41
-    protected $schema;
42
-
43
-    /**
44
-     * The Validator class that gets asked to do the validation of the config.
45
-     *
46
-     * @since 0.1.0
47
-     *
48
-     * @var Validator
49
-     */
50
-    protected $validator;
51
-
52
-    /**
53
-     * Instantiate the Config object.
54
-     *
55
-     * It accepts either an array with the configuration settings, or a
56
-     * filename pointing to a PHP file it can include.
57
-     *
58
-     * @since 0.1.0
59
-     * @since 0.1.6 Accepts a delimiter to parse configuration keys.
60
-     *
61
-     * @param array|string         $config    Array with settings or filename for the
62
-     *                                        settings file.
63
-     * @param Schema|null          $schema    Optional. Config that contains default
64
-     *                                        values that can get overwritten.
65
-     * @param Validator|null       $validator Optional. Validator class that does the
66
-     *                                        actual validation.
67
-     * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
68
-     *                                        configuration keys. Defaults to "\", "/" & ".".
69
-     *
70
-     * @throws InvalidConfigurationSourceException If the config source is not a string or array.
71
-     * @throws FailedToInstantiateParentException  If the parent class could not be instantiated.
72
-     * @throws FailedToLoadConfigException         If loading of the config source failed.
73
-     * @throws FailedToResolveConfigException      If the config file could not be resolved.
74
-     * @throws InvalidConfigException              If the config file is not valid.
75
-     */
76
-    public function __construct(
77
-        $config,
78
-        Schema $schema = null,
79
-        Validator $validator = null,
80
-        $delimiter = null
81
-    ) {
82
-        $this->schema    = $schema;
83
-        $this->validator = $validator;
84
-
85
-        // Make sure $config is either a string or array.
86
-        if (! (is_string($config) || is_array($config))) {
87
-            throw new InvalidConfigurationSourceException(
88
-                sprintf(
89
-                    _('Invalid configuration source: %1$s'),
90
-                    print_r($config, true)
91
-                )
92
-            );
93
-        }
94
-
95
-        if (is_string($config)) {
96
-            $config = Loader::load($config);
97
-        }
98
-
99
-        // Run the $config through the OptionsResolver.
100
-        Assert\that($config)->isArray();
101
-        $config = $this->resolveOptions($config);
102
-
103
-        // Instantiate the parent class.
104
-        try {
105
-            parent::__construct($config, $delimiter);
106
-        } catch (Exception $exception) {
107
-            throw new FailedToInstantiateParentException(
108
-                sprintf(
109
-                    _('Could not instantiate the configuration through its parent. Reason: %1$s'),
110
-                    $exception->getMessage()
111
-                )
112
-            );
113
-        }
114
-
115
-        // Finally, validate the resulting config.
116
-        if (! $this->isValid()) {
117
-            throw new InvalidConfigException(
118
-                sprintf(
119
-                    _('ConfigInterface file is not valid: %1$s'),
120
-                    print_r($config, true)
121
-                )
122
-            );
123
-        }
124
-    }
125
-
126
-    /**
127
-     * Validate the Config file.
128
-     *
129
-     * @since  0.1.0
130
-     *
131
-     * @return boolean
132
-     */
133
-    public function isValid()
134
-    {
135
-        if ($this->validator) {
136
-            return $this->validator->isValid($this);
137
-        }
138
-
139
-        return true;
140
-    }
141
-
142
-    /**
143
-     * Process the passed-in defaults and merge them with the new values, while
144
-     * checking that all required options are set.
145
-     *
146
-     * @since 0.1.0
147
-     *
148
-     * @param array $config Configuration settings to resolve.
149
-     *
150
-     * @return array Resolved configuration settings.
151
-     * @throws FailedToResolveConfigException If there are errors while resolving the options.
152
-     */
153
-    protected function resolveOptions($config)
154
-    {
155
-        if (! $this->schema) {
156
-            return $config;
157
-        }
158
-
159
-        try {
160
-            $resolver = new OptionsResolver();
161
-            if ($this->configureOptions($resolver)) {
162
-                $config = $resolver->resolve($config);
163
-            }
164
-        } catch (Exception $exception) {
165
-            throw new FailedToResolveConfigException(
166
-                sprintf(
167
-                    _('Error while resolving config options: %1$s'),
168
-                    $exception->getMessage()
169
-                )
170
-            );
171
-        }
172
-
173
-        return $config;
174
-    }
175
-
176
-    /**
177
-     * Configure the possible and required options for the Config.
178
-     *
179
-     * This should return a bool to let the resolve_options() know whether the
180
-     * actual resolving needs to be done or not.
181
-     *
182
-     * @since 0.1.0
183
-     *
184
-     * @param OptionsResolver $resolver Reference to the OptionsResolver
185
-     *                                  instance.
186
-     *
187
-     * @return bool Whether to do the resolving.
188
-     * @throws FailedToResolveConfigException If there are errors while processing.
189
-     */
190
-    protected function configureOptions(OptionsResolver $resolver)
191
-    {
192
-        $defined  = $this->schema->getDefinedOptions();
193
-        $defaults = $this->schema->getDefaultOptions();
194
-        $required = $this->schema->getRequiredOptions();
195
-
196
-        if (! $defined && ! $defaults && ! $required) {
197
-            return false;
198
-        }
199
-
200
-        try {
201
-            if ($defined) {
202
-                $resolver->setDefined($defined);
203
-            }
204
-            if ($defaults) {
205
-                $resolver->setDefaults($defaults);
206
-            }
207
-            if ($required) {
208
-                $resolver->setRequired($required);
209
-            }
210
-        } catch (Exception $exception) {
211
-            throw new FailedToResolveConfigException(
212
-                sprintf(
213
-                    _('Error while processing config options: %1$s'),
214
-                    $exception->getMessage()
215
-                )
216
-            );
217
-        }
218
-
219
-        return true;
220
-    }
36
+	/**
37
+	 * The schema of the Config file.
38
+	 *
39
+	 * @var Schema
40
+	 */
41
+	protected $schema;
42
+
43
+	/**
44
+	 * The Validator class that gets asked to do the validation of the config.
45
+	 *
46
+	 * @since 0.1.0
47
+	 *
48
+	 * @var Validator
49
+	 */
50
+	protected $validator;
51
+
52
+	/**
53
+	 * Instantiate the Config object.
54
+	 *
55
+	 * It accepts either an array with the configuration settings, or a
56
+	 * filename pointing to a PHP file it can include.
57
+	 *
58
+	 * @since 0.1.0
59
+	 * @since 0.1.6 Accepts a delimiter to parse configuration keys.
60
+	 *
61
+	 * @param array|string         $config    Array with settings or filename for the
62
+	 *                                        settings file.
63
+	 * @param Schema|null          $schema    Optional. Config that contains default
64
+	 *                                        values that can get overwritten.
65
+	 * @param Validator|null       $validator Optional. Validator class that does the
66
+	 *                                        actual validation.
67
+	 * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
68
+	 *                                        configuration keys. Defaults to "\", "/" & ".".
69
+	 *
70
+	 * @throws InvalidConfigurationSourceException If the config source is not a string or array.
71
+	 * @throws FailedToInstantiateParentException  If the parent class could not be instantiated.
72
+	 * @throws FailedToLoadConfigException         If loading of the config source failed.
73
+	 * @throws FailedToResolveConfigException      If the config file could not be resolved.
74
+	 * @throws InvalidConfigException              If the config file is not valid.
75
+	 */
76
+	public function __construct(
77
+		$config,
78
+		Schema $schema = null,
79
+		Validator $validator = null,
80
+		$delimiter = null
81
+	) {
82
+		$this->schema    = $schema;
83
+		$this->validator = $validator;
84
+
85
+		// Make sure $config is either a string or array.
86
+		if (! (is_string($config) || is_array($config))) {
87
+			throw new InvalidConfigurationSourceException(
88
+				sprintf(
89
+					_('Invalid configuration source: %1$s'),
90
+					print_r($config, true)
91
+				)
92
+			);
93
+		}
94
+
95
+		if (is_string($config)) {
96
+			$config = Loader::load($config);
97
+		}
98
+
99
+		// Run the $config through the OptionsResolver.
100
+		Assert\that($config)->isArray();
101
+		$config = $this->resolveOptions($config);
102
+
103
+		// Instantiate the parent class.
104
+		try {
105
+			parent::__construct($config, $delimiter);
106
+		} catch (Exception $exception) {
107
+			throw new FailedToInstantiateParentException(
108
+				sprintf(
109
+					_('Could not instantiate the configuration through its parent. Reason: %1$s'),
110
+					$exception->getMessage()
111
+				)
112
+			);
113
+		}
114
+
115
+		// Finally, validate the resulting config.
116
+		if (! $this->isValid()) {
117
+			throw new InvalidConfigException(
118
+				sprintf(
119
+					_('ConfigInterface file is not valid: %1$s'),
120
+					print_r($config, true)
121
+				)
122
+			);
123
+		}
124
+	}
125
+
126
+	/**
127
+	 * Validate the Config file.
128
+	 *
129
+	 * @since  0.1.0
130
+	 *
131
+	 * @return boolean
132
+	 */
133
+	public function isValid()
134
+	{
135
+		if ($this->validator) {
136
+			return $this->validator->isValid($this);
137
+		}
138
+
139
+		return true;
140
+	}
141
+
142
+	/**
143
+	 * Process the passed-in defaults and merge them with the new values, while
144
+	 * checking that all required options are set.
145
+	 *
146
+	 * @since 0.1.0
147
+	 *
148
+	 * @param array $config Configuration settings to resolve.
149
+	 *
150
+	 * @return array Resolved configuration settings.
151
+	 * @throws FailedToResolveConfigException If there are errors while resolving the options.
152
+	 */
153
+	protected function resolveOptions($config)
154
+	{
155
+		if (! $this->schema) {
156
+			return $config;
157
+		}
158
+
159
+		try {
160
+			$resolver = new OptionsResolver();
161
+			if ($this->configureOptions($resolver)) {
162
+				$config = $resolver->resolve($config);
163
+			}
164
+		} catch (Exception $exception) {
165
+			throw new FailedToResolveConfigException(
166
+				sprintf(
167
+					_('Error while resolving config options: %1$s'),
168
+					$exception->getMessage()
169
+				)
170
+			);
171
+		}
172
+
173
+		return $config;
174
+	}
175
+
176
+	/**
177
+	 * Configure the possible and required options for the Config.
178
+	 *
179
+	 * This should return a bool to let the resolve_options() know whether the
180
+	 * actual resolving needs to be done or not.
181
+	 *
182
+	 * @since 0.1.0
183
+	 *
184
+	 * @param OptionsResolver $resolver Reference to the OptionsResolver
185
+	 *                                  instance.
186
+	 *
187
+	 * @return bool Whether to do the resolving.
188
+	 * @throws FailedToResolveConfigException If there are errors while processing.
189
+	 */
190
+	protected function configureOptions(OptionsResolver $resolver)
191
+	{
192
+		$defined  = $this->schema->getDefinedOptions();
193
+		$defaults = $this->schema->getDefaultOptions();
194
+		$required = $this->schema->getRequiredOptions();
195
+
196
+		if (! $defined && ! $defaults && ! $required) {
197
+			return false;
198
+		}
199
+
200
+		try {
201
+			if ($defined) {
202
+				$resolver->setDefined($defined);
203
+			}
204
+			if ($defaults) {
205
+				$resolver->setDefaults($defaults);
206
+			}
207
+			if ($required) {
208
+				$resolver->setRequired($required);
209
+			}
210
+		} catch (Exception $exception) {
211
+			throw new FailedToResolveConfigException(
212
+				sprintf(
213
+					_('Error while processing config options: %1$s'),
214
+					$exception->getMessage()
215
+				)
216
+			);
217
+		}
218
+
219
+		return true;
220
+	}
221 221
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         $this->validator = $validator;
84 84
 
85 85
         // Make sure $config is either a string or array.
86
-        if (! (is_string($config) || is_array($config))) {
86
+        if ( ! (is_string($config) || is_array($config))) {
87 87
             throw new InvalidConfigurationSourceException(
88 88
                 sprintf(
89 89
                     _('Invalid configuration source: %1$s'),
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         }
114 114
 
115 115
         // Finally, validate the resulting config.
116
-        if (! $this->isValid()) {
116
+        if ( ! $this->isValid()) {
117 117
             throw new InvalidConfigException(
118 118
                 sprintf(
119 119
                     _('ConfigInterface file is not valid: %1$s'),
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     protected function resolveOptions($config)
154 154
     {
155
-        if (! $this->schema) {
155
+        if ( ! $this->schema) {
156 156
             return $config;
157 157
         }
158 158
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         $defaults = $this->schema->getDefaultOptions();
194 194
         $required = $this->schema->getRequiredOptions();
195 195
 
196
-        if (! $defined && ! $defaults && ! $required) {
196
+        if ( ! $defined && ! $defaults && ! $required) {
197 197
             return false;
198 198
         }
199 199
 
Please login to merge, or discard this patch.