Skip to content

[OptionsResolver] Add $triggerDeprecation arg to offsetGet() method in Options interface #31799

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
5 changes: 5 additions & 0 deletions src/Symfony/Component/OptionsResolver/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.0.0
-----

* added `offsetGet()` method to the `Options` interface with a new boolean argument `$triggerDeprecation`

4.3.0
-----

Expand Down
24 changes: 22 additions & 2 deletions src/Symfony/Component/OptionsResolver/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@

namespace Symfony\Component\OptionsResolver;

use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\NoSuchOptionException;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;

/**
* Contains resolved option values.
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Tobias Schultze <http://tobion.de>
*
* @method mixed offsetGet(string $option, bool $triggerDeprecation = true)
*/
interface Options extends \ArrayAccess, \Countable
{
/**
* Returns the resolved value of an option.
*
* @param string $option The option name
* @param bool $triggerDeprecation Whether to trigger the deprecation or not
*
* @return mixed The option value
*
* @throws AccessException If accessing this method outside of
* {@link resolve()}
* @throws NoSuchOptionException If the option is not set
* @throws InvalidOptionsException If the option doesn't fulfill the
* specified validation rules
* @throws OptionDefinitionException If there is a cyclic dependency between
Copy link
Member

Choose a reason for hiding this comment

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

all this is not a minor change: was it implicitly the definition of the contracts of the interface before?
also, does it make sense to have all this at the abstraction level? or are they implementation details of OptionsResolver, the implementation?

* lazy options and/or normalizers
*/
public function offsetGet($option, bool $triggerDeprecation = true);
}
19 changes: 2 additions & 17 deletions src/Symfony/Component/OptionsResolver/OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,29 +825,14 @@ public function resolve(array $options = [])
}

/**
* Returns the resolved value of an option.
*
* @param string $option The option name
* @param bool $triggerDeprecation Whether to trigger the deprecation or not (true by default)
*
* @return mixed The option value
*
* @throws AccessException If accessing this method outside of
* {@link resolve()}
* @throws NoSuchOptionException If the option is not set
* @throws InvalidOptionsException If the option doesn't fulfill the
* specified validation rules
* @throws OptionDefinitionException If there is a cyclic dependency between
* lazy options and/or normalizers
* {@inheritdoc}
*/
public function offsetGet($option/*, bool $triggerDeprecation = true*/)
public function offsetGet($option, bool $triggerDeprecation = true)
{
if (!$this->locked) {
throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
}

$triggerDeprecation = 1 === \func_num_args() || \func_get_arg(1);

// Shortcut for resolved options
if (isset($this->resolved[$option]) || \array_key_exists($option, $this->resolved)) {
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || $this->calling) && \is_string($this->deprecated[$option])) {
Expand Down