mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 18:50:14 +02:00
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>
57 lines
1.5 KiB
PHP
57 lines
1.5 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;
|
|
|
|
/**
|
|
* Exception class for Size rule.
|
|
*
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
class SizeException extends NestedValidationException
|
|
{
|
|
public const BOTH = 'both';
|
|
public const LOWER = 'lower';
|
|
public const GREATER = 'greater';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static $defaultTemplates = [
|
|
self::MODE_DEFAULT => [
|
|
self::BOTH => '{{name}} must be between {{minSize}} and {{maxSize}}',
|
|
self::LOWER => '{{name}} must be greater than {{minSize}}',
|
|
self::GREATER => '{{name}} must be lower than {{maxSize}}',
|
|
],
|
|
self::MODE_NEGATIVE => [
|
|
self::BOTH => '{{name}} must not be between {{minSize}} and {{maxSize}}',
|
|
self::LOWER => '{{name}} must not be greater than {{minSize}}',
|
|
self::GREATER => '{{name}} must not be lower than {{maxSize}}',
|
|
],
|
|
];
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function chooseTemplate(): string
|
|
{
|
|
if (!$this->getParam('minValue')) {
|
|
return static::GREATER;
|
|
} elseif (!$this->getParam('maxValue')) {
|
|
return static::LOWER;
|
|
}
|
|
|
|
return static::BOTH;
|
|
}
|
|
}
|