eee
This commit is contained in:
@@ -51,8 +51,10 @@ class BindForm implements InjectParameterInterface
|
||||
if ($rule instanceof RequestFilterInterface) {
|
||||
$validator->addRule($property->getName(), $rule->dispatch($object, $property->getName()));
|
||||
}
|
||||
if ($rule instanceof Binding) {
|
||||
$validator->setAlias($attribute->getName(), $rule->field);
|
||||
}
|
||||
}
|
||||
|
||||
$typeProxy = $this->_typeValidator($property);
|
||||
$validator->addRule($property->getName(), [$typeProxy, false]);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,12 @@ class Validator
|
||||
protected object $formData;
|
||||
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $alias = [];
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -71,6 +77,17 @@ class Validator
|
||||
return $this->formData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @param string $property
|
||||
* @return void
|
||||
*/
|
||||
public function setAlias(string $alias, string $property): void
|
||||
{
|
||||
$this->alias[$alias] = $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $rule
|
||||
@@ -107,17 +124,18 @@ class Validator
|
||||
foreach ($this->rules as $name => $rules) {
|
||||
/** @var array<array<TypesProxy,string>> $typeValidator */
|
||||
$typeValidator = array_pop($rules);
|
||||
if (!isset($params[$name])) {
|
||||
$key = $this->alias[$name];
|
||||
if (!isset($params[$key])) {
|
||||
if ($rules[0] instanceof RequiredValidatorFilter) {
|
||||
return $this->addError('The request field ' . $name . ' is mandatory and indispensable');
|
||||
}
|
||||
if (!$typeValidator[0]->allowsNull) {
|
||||
return $this->addError('The request field ' . $name . ' parameter cannot be null');
|
||||
}
|
||||
$params[$name] = null;
|
||||
$params[$key] = null;
|
||||
}
|
||||
|
||||
if (!call_user_func($typeValidator, $this->formData, $name, $params[$name])) {
|
||||
if (!call_user_func($typeValidator, $this->formData, $name, $params[$key])) {
|
||||
return $this->addError('The parameter type used in the request field ' . $name . ' is incorrect');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user