diff --git a/src/Validator/BindForm.php b/src/Validator/BindForm.php index 5ee05a9..78af1ab 100644 --- a/src/Validator/BindForm.php +++ b/src/Validator/BindForm.php @@ -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]); } diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 9bffa6e..9ef6706 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -40,6 +40,12 @@ class Validator protected object $formData; + /** + * @var array + */ + 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> $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'); }