8000 Extracted OptionsResolver component out of Form by webmozart · Pull Request #3968 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Extracted OptionsResolver component out of Form #3968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 15, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[OptionsResolver] Fixed issues mentioned in the PR comments
  • Loading branch information
webmozart committed May 14, 2012
commit 1c5f6c76c10fe5daadeea11150ebf3c606c4f3e7
33 changes: 16 additions & 17 deletions src/Symfony/Component/OptionsResolver/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@

namespace Symfony\Component\OptionsResolver;

use ArrayAccess;
use Closure;
use Iterator;
use OutOfBoundsException;
use Countable;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;

/**
* Container for resolving inter-dependent options.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class Options implements ArrayAccess, Iterator, Countable
class Options implements \ArrayAccess, \Iterator, \Countable
{
/**
* A list of option values and LazyOption instances.
Expand All @@ -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
Expand Down Expand Up @@ -146,6 +141,10 @@ public function overload($option, $value)

$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)) {
Expand All @@ -171,7 +170,7 @@ public function overload($option, $value)
*
* @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.
*/
Expand All @@ -180,7 +179,7 @@ public function get($option)
$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])) {
Expand Down Expand Up @@ -268,7 +267,7 @@ public function all()
*
* @return Boolean Whether the option exists.
*
* @see ArrayAccess::offsetExists()
* @see \ArrayAccess::offsetExists()
*/
public function offsetExists($option)
{
Expand All @@ -282,11 +281,11 @@ public function offsetExists($option)
*
* @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)
{
Expand All @@ -304,7 +303,7 @@ public function offsetGet($option)
* Once options are read, the container
* becomes immutable.
*
* @see ArrayAccess::offsetSet()
* @see \ArrayAccess::offsetSet()
*/
public function offsetSet($option, $value)
{
Expand All @@ -320,7 +319,7 @@ public function offsetSet($option, $value)
* Once options are read, the container
* becomes immutable.
*
* @see ArrayAccess::offsetUnset()
* @see \ArrayAccess::offsetUnset()
*/
public function offsetUnset($option)
{
Expand Down Expand Up @@ -418,9 +417,9 @@ private function resolve($option)
*
* @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;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/OptionsResolver/OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,12 @@ private function validateOptionNames(array $optionNames)

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)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/OptionsResolver/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OptionsResolver Component
======================
=========================

OptionsResolver helps at configuring objects with option arrays.

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/OptionsResolver/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
0