Skip to content

[OptionsResolver] added ability to allow extra options #7985

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 20 additions & 1 deletion src/Symfony/Component/OptionsResolver/OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class OptionsResolver implements OptionsResolverInterface
*/
private $allowedTypes = array();

/**
* Whether to allow extra options.
* @var Boolean
*/
private $allowExtraOptions = false;

/**
* Creates a new instance.
*/
Expand All @@ -69,6 +75,16 @@ public function __clone()
$this->defaultOptions = clone $this->defaultOptions;
}

/**
* Enable/Disable extra options.
*
* @param Boolean $value
*/
public function setAllowExtraOptions($value = true)
{
$this->allowExtraOptions = $value;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -216,7 +232,10 @@ public function isRequired($option)
*/
public function resolve(array $options = array())
{
$this->validateOptionsExistence($options);
if (!$this->allowExtraOptions) {
$this->validateOptionsExistence($options);
}

$this->validateOptionsCompleteness($options);

// Make sure this method can be called multiple times
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,15 @@ public function testClone()
'three' => '3',
), $clone->resolve());
}

public function testExtraOptions()
{
$this->resolver->setDefaults(array('one' => '1'));
$this->resolver->setAllowExtraOptions();

$this->assertEquals(array(
'one' => '1',
'two' => '2'
), $this->resolver->resolve(array('two' => '2')));
}
}