protected function _sanitize($attribute, $filter, $parameters, $value)
{
$srcValue = $value;
if (isset($this->_filters[$filter])) {
$value = call_user_func_array($this->_filters[$filter], [$value, $parameters]);
} elseif (function_exists($filter)) {
$value = call_user_func_array($filter, array_merge([$value], $parameters));
} else {
throw new FilterException('`:name` filter is not be recognized', ['name' => $filter]);
}
if ($value === null) {
if (is_string($this->_messages)) {
if (!Text::contains($this->_messages, '.')) {
$file = '@manaphp/Http/Filter/Messages/' . $this->_messages . '.php';
} else {
$file = $this->_messages;
}
if (!$this->filesystem->fileExists($file)) {
throw new FilterException('`:file` filter message template file is not exists', ['file' => $file]);
}
/** @noinspection PhpIncludeInspection */
$this->_messages = (require $this->alias->resolve($file));
}
if (isset($this->_messages[$filter])) {
$message = $this->_messages[$filter];
} else {
$message = $this->_defaultMessage;
}
$bind = [];
$bind['filter'] = $filter;
$bind['attribute'] = isset($this->_attributes[$attribute]) ? $this->_attributes[$attribute] : $attribute;
$bind['value'] = $srcValue;
foreach ($parameters as $k => $parameter) {
$bind['parameter[' . $k . ']'] = $parameter;
}
throw new FilterException($message, $bind);
}
return $value;
}