Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c5f6c7

Browse files
committed
[OptionsResolver] Fixed issues mentioned in the PR comments
1 parent d60626e commit 1c5f6c7

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/Symfony/Component/OptionsResolver/Options.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@
1111

1212
namespace Symfony\Component\OptionsResolver;
1313

14-
use ArrayAccess;
15-
use Closure;
16-
use Iterator;
17-
use OutOfBoundsException;
18-
use Countable;
1914
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2015

2116
/**
2217
* Container for resolving inter-dependent options.
2318
*
2419
* @author Bernhard Schussek <[email protected]>
2520
*/
26-
class Options implements ArrayAccess, Iterator, Countable
21+
class Options implements \ArrayAccess, \Iterator, \Countable
2722
{
2823
/**
2924
* A list of option values and LazyOption instances.
@@ -46,9 +41,9 @@ class Options implements ArrayAccess, Iterator, Countable
4641
/**
4742
* Whether at least one option has already been read.
4843
*
49-
* Once reading, the options cannot be changed anymore. This is
44+
* Once read, the options cannot be changed anymore. This is
5045
* necessary in order to avoid inconsistencies during the resolving
51-
* process. If any option is changed after reading, all evaluated
46+
* process. If any option is changed after being read, all evaluated
5247
* lazy options that depend on this option would become invalid.
5348
*
5449
* @var Boolean
@@ -146,6 +141,10 @@ public function overload($option, $value)
146141

147142
$newValue = $value;
148143

144+
// Reset lazy flag and locks by default
145+
unset($this->lock[$option]);
146+
unset($this->lazy[$option]);
147+
149148
// If an option is a closure that should be evaluated lazily, store it
150149
// inside a LazyOption instance.
151150
if ($this->isEvaluatedLazily($value)) {
@@ -171,7 +170,7 @@ public function overload($option, $value)
171170
*
172171
* @return mixed The option value.
173172
*
174-
* @throws OutOfBoundsException If the option does not exist.
173+
* @throws \OutOfBoundsException If the option does not exist.
175174
* @throws OptionDefinitionException If a cyclic dependency is detected
176175
* between two lazy options.
177176
*/
@@ -180,7 +179,7 @@ public function get($option)
180179
$this->reading = true;
181180

182181
if (!array_key_exists($option, $this->options)) {
183-
throw new OutOfBoundsException('The option "' . $option . '" does not exist.');
182+
throw new \OutOfBoundsException('The option "' . $option . '" does not exist.');
184183
}
185184

186185
if (isset($this->lazy[$option])) {
@@ -268,7 +267,7 @@ public function all()
268267
*
269268
* @return Boolean Whether the option exists.
270269
*
271-
* @see ArrayAccess::offsetExists()
270+
* @see \ArrayAccess::offsetExists()
272271
*/
273272
public function offsetExists($option)
274273
{
@@ -282,11 +281,11 @@ public function offsetExists($option)
282281
*
283282
* @return mixed The option value.
284283
*
285-
* @throws OutOfBoundsException If the option does not exist.
284+
* @throws \OutOfBoundsException If the option does not exist.
286285
* @throws OptionDefinitionException If a cyclic dependency is detected
287286
* between two lazy options.
288287
*
289-
* @see ArrayAccess::offsetGet()
288+
* @see \ArrayAccess::offsetGet()
290289
*/
291290
public function offsetGet($option)
292291
{
@@ -304,7 +303,7 @@ public function offsetGet($option)
304303
* Once options are read, the container
305304
* becomes immutable.
306305
*
307-
* @see ArrayAccess::offsetSet()
306+
* @see \ArrayAccess::offsetSet()
308307
*/
309308
public function offsetSet($option, $value)
310309
{
@@ -320,7 +319,7 @@ public function offsetSet($option, $value)
320319
* Once options are read, the container
321320
* becomes immutable.
322321
*
323-
* @see ArrayAccess::offsetUnset()
322+
* @see \ArrayAccess::offsetUnset()
324323
*/
325324
public function offsetUnset($option)
326325
{
@@ -418,9 +417,9 @@ private function resolve($option)
418417
*
419418
* @return Boolean Whether it is a lazy option closure.
420419
*/
421-
private static function isEvaluatedLazily($value)
420+
static private function isEvaluatedLazily($value)
422421
{
423-
if (!$value instanceof Closure) {
422+
if (!$value instanceof \Closure) {
424423
return false;
425424
}
426425

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ private function validateOptionNames(array $optionNames)
269269

270270
if (count($diff) > 0) {
271271
if (count($diff) > 1) {
272-
throw new MissingOptionsException(sprintf('The options "%s" are missing.', implode('", "', $diff)));
272+
throw new MissingOptionsException(sprintf('The required options "%s" are missing.',
273+
implode('",
274+
"', $diff)));
273275
}
274276

275-
throw new MissingOptionsException(sprintf('The option "%s" is missing.', current($diff)));
277+
throw new MissingOptionsException(sprintf('The required option "%s" is missing.', current($diff)));
276278
}
277279
}
278280

src/Symfony/Component/OptionsResolver/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
OptionsResolver Component
2-
======================
2+
=========================
33

44
OptionsResolver helps at configuring objects with option arrays.
55

src/Symfony/Component/OptionsResolver/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "symfony/options-resolver",
33
"type": "library",
44
"description": "Symfony OptionsResolver Component",
5-
"keywords": [],
5+
"keywords": ["options", "config", "configuration"],
66
"homepage": "http://symfony.com",
77
"license": "MIT",
88
"authors": [

0 commit comments

Comments
 (0)