From 1c5f6c76c10fe5daadeea11150ebf3c606c4f3e7 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 14 May 2012 19:34:05 +0200 Subject: [PATCH] [OptionsResolver] Fixed issues mentioned in the PR comments --- .../Component/OptionsResolver/Options.php | 33 +++++++++---------- .../OptionsResolver/OptionsResolver.php | 6 ++-- .../Component/OptionsResolver/README.md | 2 +- .../Component/OptionsResolver/composer.json | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Options.php b/src/Symfony/Component/OptionsResolver/Options.php index 25e47677f3..49c2eef62c 100644 --- a/src/Symfony/Component/OptionsResolver/Options.php +++ b/src/Symfony/Component/OptionsResolver/Options.php @@ -11,11 +11,6 @@ namespace Symfony\Component\OptionsResolver; -use ArrayAccess; -use Closure; -use Iterator; -use OutOfBoundsException; -use Countable; use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException; /** @@ -23,7 +18,7 @@ use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException; * * @author Bernhard Schussek */ -class Options implements ArrayAccess, Iterator, Countable +class Options implements \ArrayAccess, \Iterator, \Countable { /** * A list of option values and LazyOption instances. @@ -46,9 +41,9 @@ class Options implements ArrayAccess, Iterator, Countable /** * Whether at least one option has already been read. * - * Once reading, the options cannot be changed anymore. This is + * Once read, the options cannot be changed anymore. This is * necessary in order to avoid inconsistencies during the resolving - * process. If any option is changed after reading, all evaluated + * process. If any option is changed after being read, all evaluated * lazy options that depend on this option would become invalid. * * @var Boolean @@ -146,6 +141,10 @@ class Options implements ArrayAccess, Iterator, Countable $newValue = $value; + // Reset lazy flag and locks by default + unset($this->lock[$option]); + unset($this->lazy[$option]); + // If an option is a closure that should be evaluated lazily, store it // inside a LazyOption instance. if ($this->isEvaluatedLazily($value)) { @@ -171,7 +170,7 @@ class Options implements ArrayAccess, Iterator, Countable * * @return mixed The option value. * - * @throws OutOfBoundsException If the option does not exist. + * @throws \OutOfBoundsException If the option does not exist. * @throws OptionDefinitionException If a cyclic dependency is detected * between two lazy options. */ @@ -180,7 +179,7 @@ class Options implements ArrayAccess, Iterator, Countable $this->reading = true; if (!array_key_exists($option, $this->options)) { - throw new OutOfBoundsException('The option "' . $option . '" does not exist.'); + throw new \OutOfBoundsException('The option "' . $option . '" does not exist.'); } if (isset($this->lazy[$option])) { @@ -268,7 +267,7 @@ class Options implements ArrayAccess, Iterator, Countable * * @return Boolean Whether the option exists. * - * @see ArrayAccess::offsetExists() + * @see \ArrayAccess::offsetExists() */ public function offsetExists($option) { @@ -282,11 +281,11 @@ class Options implements ArrayAccess, Iterator, Countable * * @return mixed The option value. * - * @throws OutOfBoundsException If the option does not exist. + * @throws \OutOfBoundsException If the option does not exist. * @throws OptionDefinitionException If a cyclic dependency is detected * between two lazy options. * - * @see ArrayAccess::offsetGet() + * @see \ArrayAccess::offsetGet() */ public function offsetGet($option) { @@ -304,7 +303,7 @@ class Options implements ArrayAccess, Iterator, Countable * Once options are read, the container * becomes immutable. * - * @see ArrayAccess::offsetSet() + * @see \ArrayAccess::offsetSet() */ public function offsetSet($option, $value) { @@ -320,7 +319,7 @@ class Options implements ArrayAccess, Iterator, Countable * Once options are read, the container * becomes immutable. * - * @see ArrayAccess::offsetUnset() + * @see \ArrayAccess::offsetUnset() */ public function offsetUnset($option) { @@ -418,9 +417,9 @@ class Options implements ArrayAccess, Iterator, Countable * * @return Boolean Whether it is a lazy option closure. */ - private static function isEvaluatedLazily($value) + static private function isEvaluatedLazily($value) { - if (!$value instanceof Closure) { + if (!$value instanceof \Closure) { return false; } diff --git a/src/Symfony/Component/OptionsResolver/OptionsResolver.php b/src/Symfony/Component/OptionsResolver/OptionsResolver.php index 3d1782d978..be0eb03855 100644 --- a/src/Symfony/Component/OptionsResolver/OptionsResolver.php +++ b/src/Symfony/Component/OptionsResolver/OptionsResolver.php @@ -269,10 +269,12 @@ class OptionsResolver if (count($diff) > 0) { if (count($diff) > 1) { - throw new MissingOptionsException(sprintf('The options "%s" are missing.', implode('", "', $diff))); + throw new MissingOptionsException(sprintf('The required options "%s" are missing.', + implode('", + "', $diff))); } - throw new MissingOptionsException(sprintf('The option "%s" is missing.', current($diff))); + throw new MissingOptionsException(sprintf('The required option "%s" is missing.', current($diff))); } } diff --git a/src/Symfony/Component/OptionsResolver/README.md b/src/Symfony/Component/OptionsResolver/README.md index d0bfae6ef6..c2280011e4 100644 --- a/src/Symfony/Component/OptionsResolver/README.md +++ b/src/Symfony/Component/OptionsResolver/README.md @@ -1,5 +1,5 @@ OptionsResolver Component -====================== +========================= OptionsResolver helps at configuring objects with option arrays. diff --git a/src/Symfony/Component/OptionsResolver/composer.json b/src/Symfony/Component/OptionsResolver/composer.json index bd74964548..391eed1a6f 100644 --- a/src/Symfony/Component/OptionsResolver/composer.json +++ b/src/Symfony/Component/OptionsResolver/composer.json @@ -2,7 +2,7 @@ "name": "symfony/options-resolver", "type": "library", "description": "Symfony OptionsResolver Component", - "keywords": [], + "keywords": ["options", "config", "configuration"], "homepage": "http://symfony.com", "license": "MIT", "authors": [