
| Current Path : /var/www/html/strat/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/strat/vendor/chi-teck/drupal-code-generator/src/Validator/Chained.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Validator;
/**
* Validates using a chain of validators.
*/
final class Chained {
private readonly array $validators;
/**
* @psalm-param callable(mixed): mixed ...$validators
*/
public function __construct(callable ...$validators) {
$this->validators = $validators;
}
/**
* @throws \UnexpectedValueException
*/
public function __invoke(mixed $value): mixed {
foreach ($this->validators as $validator) {
$value = $validator($value);
}
return $value;
}
/**
* Appends validators to the chain.
*/
public function with(callable ...$validators): self {
return new self(...$this->validators, ...$validators);
}
}