mirror of
https://github.com/Respect/Validation.git
synced 2024-06-03 06:12:17 +02:00
Update message after changing exception properties
This commit is contained in:
parent
29bdb0a9f6
commit
03c0bd03de
|
@ -110,14 +110,14 @@ class AbstractNestedException extends ValidationException implements NestedValid
|
|||
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
parent::setParam($name, $value);
|
||||
|
||||
if ('translator' === $name) {
|
||||
foreach ($this->getRelated(true) as $related) {
|
||||
$related->setParam($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
parent::setParam($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,9 +201,8 @@ class ValidationException extends InvalidArgumentException implements Validation
|
|||
public function configure($name, array $params = [])
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->setParams($params);
|
||||
$this->message = $this->getMainMessage();
|
||||
$this->setId($this->guessId());
|
||||
$this->setParams($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -273,6 +272,8 @@ class ValidationException extends InvalidArgumentException implements Validation
|
|||
$this->mode = $mode;
|
||||
$this->template = $this->buildTemplate();
|
||||
|
||||
$this->buildMessage();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -280,15 +281,19 @@ class ValidationException extends InvalidArgumentException implements Validation
|
|||
{
|
||||
$this->params[$key] = $value;
|
||||
|
||||
$this->buildMessage();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setParams(array $params)
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$this->setParam($key, $value);
|
||||
$this->params[$key] = $value;
|
||||
}
|
||||
|
||||
$this->buildMessage();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -305,6 +310,11 @@ class ValidationException extends InvalidArgumentException implements Validation
|
|||
return $this;
|
||||
}
|
||||
|
||||
private function buildMessage()
|
||||
{
|
||||
$this->message = $this->getMainMessage();
|
||||
}
|
||||
|
||||
protected function buildTemplate()
|
||||
{
|
||||
$templateKey = $this->chooseTemplate();
|
||||
|
|
18
tests/integration/exception_update.phpt
Normal file
18
tests/integration/exception_update.phpt
Normal file
|
@ -0,0 +1,18 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::not(v::alnum())->check('abc123');
|
||||
} catch (Exception $exception) {
|
||||
$exception->setParam('translator', function() {
|
||||
return '{{name}} não deve conter letras (a-z) ou dígitos (0-9)';
|
||||
});
|
||||
echo $exception->getMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"abc123" não deve conter letras (a-z) ou dígitos (0-9)
|
Loading…
Reference in a new issue