respect-validation/library/Exceptions/LengthException.php
Henrique Moody dd896bb12d
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>
2024-01-29 23:17:27 +01:00

37 lines
1.7 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Respect\Validation\Rules\Length;
final class LengthException extends ValidationException
{
/**
* @var array<string, array<string, string>>
*/
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
Length::TEMPLATE_BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
Length::TEMPLATE_LOWER => '{{name}} must have a length greater than {{minValue}}',
Length::TEMPLATE_LOWER_INCLUSIVE => '{{name}} must have a length greater than or equal to {{minValue}}',
Length::TEMPLATE_GREATER => '{{name}} must have a length lower than {{maxValue}}',
Length::TEMPLATE_GREATER_INCLUSIVE => '{{name}} must have a length lower than or equal to {{maxValue}}',
Length::TEMPLATE_EXACT => '{{name}} must have a length of {{maxValue}}',
],
self::MODE_NEGATIVE => [
Length::TEMPLATE_BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}',
Length::TEMPLATE_LOWER => '{{name}} must not have a length greater than {{minValue}}',
Length::TEMPLATE_LOWER_INCLUSIVE => '{{name}} must not have a length greater than or equal to {{minValue}}',
Length::TEMPLATE_GREATER => '{{name}} must not have a length lower than {{maxValue}}',
Length::TEMPLATE_GREATER_INCLUSIVE => '{{name}} must not have a length lower than or equal to {{maxValue}}',
Length::TEMPLATE_EXACT => '{{name}} must not have a length of {{maxValue}}',
],
];
}