8000 [OptionsResolver] add method `addAllowedTypesForAll()` · HeahDude/symfony@b486c62 · GitHub
[go: up one dir, main page]

Skip to content

Commit b486c62

Browse files
committed
[OptionsResolver] add method addAllowedTypesForAll()
closes symfony#15524. Set allowed types for many options or for a set of nested options.
1 parent 5121859 commit b486c62

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+
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