2022-12-24 22:10:40 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2024-01-31 22:15:08 +08:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2022-12-24 22:10:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
2024-01-31 22:15:08 +08:00
|
|
|
use Respect\Validation\Helpers\CountryInfo;
|
|
|
|
|
2022-12-24 22:10:40 +08:00
|
|
|
/**
|
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Michael Firsikov <michael.firsikov@gmail.com>
|
|
|
|
*/
|
|
|
|
final class PhoneException extends ValidationException
|
|
|
|
{
|
2024-01-31 22:15:08 +08:00
|
|
|
public const FOR_COUNTRY = 'for_country';
|
|
|
|
public const INTERNATIONAL = 'international';
|
|
|
|
|
2022-12-24 22:10:40 +08:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected $defaultTemplates = [
|
|
|
|
self::MODE_DEFAULT => [
|
2024-01-31 22:15:08 +08:00
|
|
|
self::INTERNATIONAL => '{{name}} 必须是有效的电话号码',
|
|
|
|
self::FOR_COUNTRY => '{{name}} 必须是 {{countryName}} 的有效电话号码',
|
2022-12-24 22:10:40 +08:00
|
|
|
],
|
|
|
|
self::MODE_NEGATIVE => [
|
2024-01-31 22:15:08 +08:00
|
|
|
self::INTERNATIONAL => '{{name}} 不能是有效的电话号码',
|
|
|
|
self::FOR_COUNTRY => '{{name}} 必须是 {{countryName}} 的有效电话号码',
|
|
|
|
|
2022-12-24 22:10:40 +08:00
|
|
|
],
|
|
|
|
];
|
2024-01-31 22:15:08 +08: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;
|
|
|
|
}
|
2022-12-24 22:10:40 +08:00
|
|
|
}
|