1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Respect/Validation. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandre Gomes Gaigalas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the "LICENSE.md" |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Respect\Validation\Exceptions; |
15
|
|
|
|
16
|
|
|
class LengthException extends ValidationException |
17
|
|
|
{ |
18
|
|
|
public const BOTH = 'both'; |
19
|
|
|
public const LOWER = 'lower'; |
20
|
|
|
public const GREATER = 'greater'; |
21
|
|
|
public const EXACT = 'exact'; |
22
|
|
|
|
23
|
|
|
public static $defaultTemplates = [ |
24
|
|
|
self::MODE_DEFAULT => [ |
25
|
|
|
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}', |
26
|
|
|
self::LOWER => '{{name}} must have a length greater than {{minValue}}', |
27
|
|
|
self::GREATER => '{{name}} must have a length lower than {{maxValue}}', |
28
|
|
|
self::EXACT => '{{name}} must have a length of {{maxValue}}', |
29
|
|
|
], |
30
|
|
|
self::MODE_NEGATIVE => [ |
31
|
|
|
self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}', |
32
|
|
|
self::LOWER => '{{name}} must not have a length greater than {{minValue}}', |
33
|
|
|
self::GREATER => '{{name}} must not have a length lower than {{maxValue}}', |
34
|
|
|
self::EXACT => '{{name}} must not have a length of {{maxValue}}', |
35
|
|
|
], |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
protected function chooseTemplate(): string |
39
|
|
|
{ |
40
|
|
|
if (!$this->getParam('minValue')) { |
41
|
|
|
return static::GREATER; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if (!$this->getParam('maxValue')) { |
45
|
|
|
return static::LOWER; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($this->getParam('minValue') == $this->getParam('maxValue')) { |
49
|
|
|
return self::EXACT; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return static::BOTH; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|