2013-04-29 05:35:29 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2013-04-29 05:35:29 +02:00
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
2023-02-18 22:09:26 +01:00
|
|
|
use Respect\Validation\Helpers\CountryInfo;
|
|
|
|
|
2018-11-25 17:56:04 +01:00
|
|
|
/**
|
2019-02-10 19:09:01 +01:00
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
2018-11-25 17:56:04 +01:00
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Michael Firsikov <michael.firsikov@gmail.com>
|
|
|
|
*/
|
2019-02-10 19:09:01 +01:00
|
|
|
final class PhoneException extends ValidationException
|
2013-04-29 05:35:29 +02:00
|
|
|
{
|
2023-02-18 22:09:26 +01:00
|
|
|
public const FOR_COUNTRY = 'for_country';
|
|
|
|
public const INTERNATIONAL = 'international';
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2019-02-07 21:22:10 +01:00
|
|
|
*/
|
2019-05-12 01:30:36 +02:00
|
|
|
protected $defaultTemplates = [
|
2015-10-18 03:44:47 +02:00
|
|
|
self::MODE_DEFAULT => [
|
2023-02-18 22:09:26 +01:00
|
|
|
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 => [
|
2023-02-18 22:09:26 +01:00
|
|
|
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
|
|
|
],
|
|
|
|
];
|
2023-02-18 22:09:26 +01: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
|
|
|
}
|