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
[OptionsParser] Renamed OptionsParser to OptionsResolver
  • Loading branch information
webmozart committed May 14, 2012
commit 256b7081a423caeb404c9ec838b6ee21cc7e5bab
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"symfony/http-foundation": "self.version",
"symfony/http-kernel": "self.version",
"symfony/locale": "self.version",
"symfony/options-parser": "self.version",
"symfony/options-resolver": "self.version",
"symfony/process": "self.version",
"symfony/routing": "self.version",
"symfony/security": "self.version",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Bridge\Doctrine\Form\EventListener\MergeDoctrineCollectionListener;
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

abstract class DoctrineType extends AbstractType
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Propel1/Form/Type/ModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Bridge\Propel1\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

/**
* ModelType class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToBooleanArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToBooleanArrayTransformer;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class ChoiceType extends AbstractType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class DateTimeType extends AbstractType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class DateType extends AbstractType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class FormType extends AbstractType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class TimeType extends AbstractType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
use Symfony\Component\OptionsParser\Options;
use Symfony\Component\OptionsResolver\Options;

class TimezoneType extends AbstractType
{
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Form/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TypeDefinitionException;
use Symfony\Component\OptionsParser\OptionsParser;
use Symfony\Component\OptionsResolver\OptionsResolver;

class FormFactory implements FormFactoryInterface
{
Expand Down Expand Up @@ -221,7 +221,7 @@ public function createNamedBuilder($type, $name, $data = null, array $options =
$types = array();
$optionValues = array();
$knownOptions = array();
$optionsParser = new OptionsParser();
$optionsResolv 10000 er = new OptionsResolver();

// Bottom-up determination of the type hierarchy
// Start with the actual type and look for the parent type
Expand Down Expand Up @@ -255,14 +255,14 @@ public function createNamedBuilder($type, $name, $data = null, array $options =
// options. Default options of children override default options
// of parents.
$typeOptions = $type->getDefaultOptions();
$optionsParser->setDefaults($typeOptions);
$optionsParser->addAllowedValues($type->getAllowedOptionValues());
$optionsResolver->setDefaults($typeOptions);
$optionsResolver->addAllowedValues($type->getAllowedOptionValues());
$knownOptions = array_merge($knownOptions, array_keys($typeOptions));

foreach ($type->getExtensions() as $typeExtension) {
$extensionOptions = $typeExtension->getDefaultOptions();
$optionsParser->setDefaults($extensionOptions);
$optionsParser->addAllowedValues($typeExtension->getAllowedOptionValues());
$optionsResolver->setDefaults($extensionOptions);
$optionsResolver->addAllowedValues($typeExtension->getAllowedOptionValues());
$knownOptions = array_merge($knownOptions, array_keys($extensionOptions));
}
}
Expand All @@ -278,7 +278,7 @@ public function createNamedBuilder($type, $name, $data = null, array $options =
}

// Resolve options
$options = $optionsParser->parse($options);
$options = $optionsResolver->resolve($options);

for ($i = 0, $l = count($types); $i < $l && !$builder; ++$i) {
$builder = $types[$i]->createBuilder($name, $this, $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp()
}

/**
* @expectedException Symfony\Component\OptionsParser\Exception\InvalidOptionsException
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testInvalidWidgetOption()
{
Expand All @@ -33,7 +33,7 @@ public function testInvalidWidgetOption()
}

/**
* @expectedException Symfony\Component\OptionsParser\Exception\InvalidOptionsException
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testInvalidInputOption()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/FormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function testCreateNamedBuilderExpectsBuilderToBeReturned()
}

/**
* @expectedException Symfony\Component\OptionsParser\Exception\InvalidOptionsException
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testCreateNamedBuilderExpectsOptionsToExist()
{
Expand All @@ -292,7 +292,7 @@ public function testCreateNamedBuilderExpectsOptionsToExist()
}

/**
* @expectedException Symfony\Component\OptionsParser\Exception\InvalidOptionsException
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testCreateNamedBuilderExpectsOptionsToBeInValidRange()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.3.3",
"symfony/event-dispatcher": "2.1.*",
"symfony/locale": "2.1.*",
"symfony/options-parser": "2.1.*"
"symfony/options-resolver": "2.1.*"
},
"require-dev": {
"symfony/validator": "2.1.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should not be executable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not.. why should it be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH says it is:

...mponent/Form/Exception/InvalidOptionException.php → .../OptionsResolver/Exception/ExceptionInterface.php 100644 → 100755

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it possible to display this information? It is not shown for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You fixed it in this commit: webmozart@d60626e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/

namespace Symfony\Component\OptionsParser\Exception;
namespace Symfony\Component\OptionsResolver\Exception;

/**
* Marker interface for the Options component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser\Exception;
namespace Symfony\Component\OptionsResolver\Exception;

/**
* Exception thrown when an invalid option is passed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser\Exception;
namespace Symfony\Component\OptionsResolver\Exception;

/**
* Exception thrown when a required option is missing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser\Exception;
namespace Symfony\Component\OptionsResolver\Exception;

/**
* Thrown when an option definition is invalid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser;
namespace Symfony\Component\OptionsResolver;

use Closure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser;
namespace Symfony\Component\OptionsResolver;

use ArrayAccess;
use Iterator;
use OutOfBoundsException;
use Symfony\Component\OptionsParser\Exception\OptionDefinitionException;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;

/**
* Container for resolving inter-dependent options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsParser;
namespace Symfony\Component\OptionsResolver;

use Symfony\Component\OptionsParser\Exception\OptionDefinitionException;
use Symfony\Component\OptionsParser\Exception\InvalidOptionsException;
use Symfony\Component\OptionsParser\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;

/**
* Helper for merging default and concrete option values.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class OptionsParser
class OptionsResolver
{
/**
* The default option values.
Expand All @@ -29,13 +29,13 @@ class OptionsParser
private $defaultOptions;

/**
* The options known by the parser.
* The options known by the resolver.
* @var array
*/
private $knownOptions = array();

/**
* The options required to be passed to parse().
* The options required to be passed to resolve().
* @var array
*/
private $requiredOptions = array();
Expand Down Expand Up @@ -100,7 +100,7 @@ public function replaceDefaults(array $defaultValues)
*
* This method is identical to `setDefaults`, only that no default values
* are configured for the options. If these options are not passed to
* parse(), they will be missing in the final options array. This can be
* resolve(), they will be missing in the final options array. This can be
* helpful if you want to determine whether an option has been set or not.
*
* @param array $optionNames A list of option names.
Expand All @@ -121,7 +121,7 @@ public function setOptional(array $optionNames)
/**
* Sets required options.
*
* If these options are not passed to parse(), an exception will be thrown.
* If these options are not passed to resolve(), an exception will be thrown.
*
* @param array $optionNames A list of option names.
*
Expand Down Expand Up @@ -189,7 +189,7 @@ public function addAllowedValues(array $allowedValues)
* @throws OptionDefinitionException If a cyclic dependency is detected
* between two lazy options.
*/
public function parse(array $options)
public function resolve(array $options)
{
$this->validateOptionNames(array_keys($options));

Expand Down
Loading
0