
| 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/Optional.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Validator;
/**
* Validates only non-empty values.
*/
final class Optional {
private readonly \Closure $validator;
/**
* @psalm-param callable(mixed): mixed $validator
*/
public function __construct(callable $validator) {
// Convert into closure as typed properties cannot be callable.
$this->validator = $validator(...);
}
/**
* @throws \UnexpectedValueException
*/
public function __invoke(mixed $value): mixed {
return $value === NULL || $value === '' || $value === [] ? $value : ($this->validator)($value);
}
}