Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WIP] [OptionsResolver] handle nested options #18134

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
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
96 changes: 96 additions & 0 deletions 96 src/Symfony/Component/OptionsResolver/NestedOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\OptionsResolver;

use Symfony\Component\OptionsResolver\Exception\AccessException;

/**
* Validates nested options and merges them with default values.
*
* This class is used internally by the OptionsResolver.
* See {@link OptionsResolver::setNested()}.
*
* @author Jules Pietri <jules@heahprod.com>
*
* @internal
*/
class NestedOptions extends OptionsResolver
{
/**
* The root options instance.
*
* @var OptionsResolver
*/
private $root;

/**
* The root option name.
*
* @var string
*/
private $rootName;

/**
* This class should only be instantiated from an OptionsResolver.
*
* See {@link OptionsResolver::setNested()}.
*
* @param string $rootName The root option name
*/
public function __construct($rootName)
{
$this->rootName = $rootName;
}

/**
* Binds the root options.
*
* This method should only be called from root OptionsResolver instance.
* See {@link OptionsResolver::__clone()}.
*
* @param OptionsResolver $root The root options
*
* @return NestedOptions This instance
*/
public function setRoot(OptionsResolver $root)
{
$this->root = $root;

return $this;
}

/**
* {@inheritdoc}
*
* This method should only be called while the root option is resolved
* {@link OptionsResolver::OffsetGet()}
*
* @throws AccessException If the root option is not locked
*/
public function resolve(array $options = array())
{
if (!$this->root->isLocked()) {
throw new AccessException(sprintf('The Nested options of "%s" can only be resolved internally while their root is resolved.', $this->rootName));
}

return parent::resolve($options);
}

/**
* {@inheritdoc}
*/
protected function normalize(\Closure $normalizer, $value)
{
// Pass the resolved parent options as third argument.
return $normalizer($this, $value, $this->root);
}
}
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/OptionsResolver/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
*/
interface Options extends \ArrayAccess, \Countable
{
const NONE = 0;
const ALL = 1;
const DEFINED = 2;
const NESTED = 3;
const EXTRA = 4;
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.