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

Commit ad7cce8

Browse filesBrowse files
committed
[OptionsResolver] add method addAllowedTypesForAll()
closes #15524. Set allowed types for many options or for a set of nested options.
1 parent 05fa38c commit ad7cce8
Copy full SHA for ad7cce8

File tree

1 file changed

+35
-0
lines changed
Filter options

1 file changed

+35
-0
lines changed

‎src/Symfony/Component/OptionsResolver/OptionsResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,41 @@ public function addAllowedTypes($option, $allowedTypes)
718718
return $this;
719719
}
720720

721+
/**
722+
* Adds allowed types for one or more options.
723+
*
724+
* If a nested option name is passed it will apply to all nested options.
725+
*
726+
* Any type for which a corresponding is_<type>() function exists is
727+
* acceptable. Additionally, fully-qualified class or interface names may
728+
* be passed.
729+
*
730+
* @param string|string[] $options One or more option names
731+
* @param string|string[] $allowedTypes One or more accepted types
732+
*
733+
* @return OptionsResolver This instance
734+
*
735+
* @throws UndefinedOptionsException If an option is undefined
736+
* @throws AccessException If called from a lazy option or normalizer
737+
*/
738+
public function addAllowTypesForAll($options, $allowedTypes)
739+
{
740+
if ($this->locked) {
741+
throw new AccessException('Allowed types cannot be added from a lazy option or normalizer.');
742+
}
743+
744+
foreach ((array) $options as $option) {
745+
// Not supported for nested options
746+
if ($this->isNested($option)) {
747+
$this->addAllowTypesForAll($this->nested[$option]->getDefinedOptions(), $allowedTypes);
748+
}
749+
750+
$this->addAllowedTypes($option, $allowedTypes);
751+
}
752+
753+
return $this;
754+
}
755+
721756
/**
722757
* Removes the option with the given name.
723758
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.