
| Current Path : /var/www/html/dinarosun/vendor/chi-teck/drupal-code-generator/src/Validator/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/dinarosun/vendor/chi-teck/drupal-code-generator/src/Validator/Choice.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Validator;
/**
* Validates that the value is one of the expected values.
*/
final class Choice {
public function __construct(
private readonly array $choices,
private readonly string $message = 'The value you selected is not a valid choice.',
) {}
/**
* @throws \UnexpectedValueException
*/
public function __invoke(mixed $value): string|int|float {
return match(FALSE) {
\is_string($value) || \is_int($value) || \is_float($value),
\in_array($value, $this->choices, TRUE) => throw new \UnexpectedValueException($this->message),
default => $value,
};
}
}