Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb486c62

Browse files
committed
[OptionsResolver] add methodaddAllowedTypesForAll()
closes#15524.Set allowed types for many options or for a set of nested options.
1 parent5121859 commitb486c62

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines 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+
publicfunctionaddAllowTypesForAll($options,$allowedTypes)
739+
{
740+
if ($this->locked) {
741+
thrownewAccessException('Allowed types cannot be added from a lazy option or normalizer.');
742+
}
743+
744+
foreach ((array)$optionsas$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)

[8]ページ先頭

©2009-2025 Movatter.jp