Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ParameterBag.php

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\HttpFoundation

Code

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);
    }
}
RSS feed
Powered by Drupal