mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Move template definitions to the rules
It's easier to identify the reason for choosing a specific message in the rule than in the exception. The same goes for the key we use to determine the templates. This change will simplify the `ValidationException` because it will already receive the template it needs to use. As a consequence, the `Factory` also becomes more straightforward. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
3334529591
commit
dd896bb12d
181 changed files with 1042 additions and 680 deletions
|
|
@ -9,27 +9,21 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use Respect\Validation\Rules\KeyNested;
|
||||
|
||||
final class KeyNestedException extends NestedValidationException implements NonOmissibleException
|
||||
{
|
||||
public const NOT_PRESENT = 'not_present';
|
||||
public const INVALID = 'invalid';
|
||||
|
||||
/**
|
||||
* @var array<string, array<string, string>>
|
||||
*/
|
||||
protected array $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::NOT_PRESENT => 'No items were found for key chain {{name}}',
|
||||
self::INVALID => 'Key chain {{name}} is not valid',
|
||||
KeyNested::TEMPLATE_NOT_PRESENT => 'No items were found for key chain {{name}}',
|
||||
KeyNested::TEMPLATE_INVALID => 'Key chain {{name}} is not valid',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::NOT_PRESENT => 'Items for key chain {{name}} must not be present',
|
||||
self::INVALID => 'Key chain {{name}} must not be valid',
|
||||
KeyNested::TEMPLATE_NOT_PRESENT => 'Items for key chain {{name}} must not be present',
|
||||
KeyNested::TEMPLATE_INVALID => 'Key chain {{name}} must not be valid',
|
||||
],
|
||||
];
|
||||
|
||||
protected function chooseTemplate(): string
|
||||
{
|
||||
return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue