function ParameterBag::getEnum
Returns the parameter value converted to an enum.
@template T of \BackedEnum
@psalm-return ($default is null ? T|null : T)
Parameters
class-string<T> $class:
?T $default:
Return value
?T
2 calls to ParameterBag::getEnum()
- InputBag::getEnum in vendor/
symfony/ http-foundation/ InputBag.php - Returns the parameter value converted to an enum.
- InputBag::getEnum in vendor/
symfony/ http-foundation/ InputBag.php - Returns the parameter value converted to an enum.
1 method overrides ParameterBag::getEnum()
- InputBag::getEnum in vendor/
symfony/ http-foundation/ InputBag.php - Returns the parameter value converted to an enum.
File
-
vendor/
symfony/ http-foundation/ ParameterBag.php, line 164
Class
- ParameterBag
- ParameterBag is a container for key/value pairs.
Namespace
Symfony\Component\HttpFoundationCode
public function getEnum(string $key, string $class, ?\BackedEnum $default = null) : ?\BackedEnum {
$value = $this->get($key);
if (null === $value) {
return $default;
}
try {
return $class::from($value);
} catch (\ValueError|\TypeError $e) {
throw new UnexpectedValueException(\sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e);
}
}