mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 11:52:34 +02:00
8c529c433e
Make the ValidationException a little bit less mutable than before. All its dependencies are now passed into the constructor. This commit also make the Factory pass the translator to the exceptions allowing to define the translator before the exception gets created. This change is not the ideal one, later I would like to not need the Singleton from the Factory to do that, but for now it seems like a good approach. One more thing that this commit does is to introduce the "id" for Exceptions. Key can be either the defined "name" or the name of the rule that throwed the exception. This method will be handy to identify exceptions better. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
class CreditCardException extends ValidationException
|
|
{
|
|
public const BRANDED = 'branded';
|
|
|
|
public static $defaultTemplates = [
|
|
self::MODE_DEFAULT => [
|
|
self::STANDARD => '{{name}} must be a valid Credit Card number',
|
|
self::BRANDED => '{{name}} must be a valid {{brand}} Credit Card number',
|
|
],
|
|
self::MODE_NEGATIVE => [
|
|
self::STANDARD => '{{name}} must not be a valid Credit Card number',
|
|
self::BRANDED => '{{name}} must not be a valid {{brand}} Credit Card number',
|
|
],
|
|
];
|
|
|
|
protected function chooseTemplate(): string
|
|
{
|
|
if (!$this->getParam('brand')) {
|
|
return static::STANDARD;
|
|
}
|
|
|
|
return static::BRANDED;
|
|
}
|
|
}
|