PHP
- 7 ответов
- 0 вопросов
3
Вклад в тег
$rules = [
new EmailRule(),
new UsernameRule(),
new UniqueRule(),
...
];
interface RuleInterface {
public function getKey(): string;
public function handle(): bool;
}
/** @var RuleInterface */
foreach ($rules as $rule) {
Valitron\Validator::addRule($rule->getKey(), function($field, $value, array $params, array $fields) use ($rule) {
return $rule->handle($field, $value, array $params, array $fields);
}, 'Everything you do is wrong. You fail.');
}