respect-validation/library/Exceptions/PhoneException.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

32 lines
991 B
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\Phone;
final class PhoneException extends ValidationException
{
public const FOR_COUNTRY = 'for_country';
public const INTERNATIONAL = 'international';
/**
* @var array<string, array<string, string>>
*/
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
Phone::TEMPLATE_INTERNATIONAL => '{{name}} must be a valid telephone number',
Phone::TEMPLATE_FOR_COUNTRY => '{{name}} must be a valid telephone number for country {{countryName}}',
],
self::MODE_NEGATIVE => [
Phone::TEMPLATE_INTERNATIONAL => '{{name}} must not be a valid telephone number',
Phone::TEMPLATE_FOR_COUNTRY => '{{name}} must not be a valid telephone number for country {{countryName}}',
],
];
}