Skip to content

Commit

Permalink
Add $triggerDeprecation arg to offsetGet() method in Options interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Jun 3, 2019
1 parent 4a437ab commit d983fd8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
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
* 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

0 comments on commit d983fd8

Please sign in to comment.