respect-validation/library/Exceptions/PhoneException.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2013-04-29 05:35:29 +02:00
<?php
2015-06-08 16:47:14 +02:00
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
2013-04-29 05:35:29 +02:00
namespace Respect\Validation\Exceptions;
use Respect\Validation\Helpers\CountryInfo;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Michael Firsikov <michael.firsikov@gmail.com>
*/
final class PhoneException extends ValidationException
2013-04-29 05:35:29 +02:00
{
public const FOR_COUNTRY = 'for_country';
public const INTERNATIONAL = 'international';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
2015-10-18 03:44:47 +02:00
self::MODE_DEFAULT => [
self::INTERNATIONAL => '{{name}} must be a valid telephone number',
self::FOR_COUNTRY => '{{name}} must be a valid telephone number for country {{countryName}}',
2015-10-18 03:44:47 +02:00
],
self::MODE_NEGATIVE => [
self::INTERNATIONAL => '{{name}} must not be a valid telephone number',
self::FOR_COUNTRY => '{{name}} must not be a valid telephone number for country {{countryName}}',
2015-10-18 03:44:47 +02:00
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
$countryCode = $this->getParam('countryCode');
if (!$countryCode) {
return self::INTERNATIONAL;
}
$countryInfo = new CountryInfo($countryCode);
$this->setParam('countryName', $countryInfo->getCountry());
return self::FOR_COUNTRY;
}
2013-04-29 05:35:29 +02:00
}