protected function applyValidator($validator, $key, $value, $messages = [])
{
try {
if ($this->isString($validator)) {
$params = $this->arr(explode(':', $validator));
$vName = '';
$validatorParams = [$this, $value, $params->removeFirst($vName)->val()];
$validator = Entity::getInstance()->getValidator($vName);
if (!$validator) {
throw new ValidationException('Validator does not exist');
}
$validator->validate(...$validatorParams);
} elseif ($this->isCallable($validator)) {
$vName = 'callable';
$validator($value, $this);
}
} catch (ValidationException $e) {
$msg = isset($messages[$vName]) ? $messages[$vName] : $e->getMessage();
$ex = new ValidationException($msg);
$ex->addError($key, $msg);
throw $ex;
}
}