|
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
|
|
|
/** |
|
17
|
|
|
* @author Alexandre Gomes Gaigalas <[email protected]> |
|
18
|
|
|
* @author Danilo Correa <[email protected]> |
|
19
|
|
|
* @author Henrique Moody <[email protected]> |
|
20
|
|
|
* @author Mazen Touati <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class LengthException extends ValidationException |
|
23
|
|
|
{ |
|
24
|
|
|
public const BOTH = 'both'; |
|
25
|
|
|
public const LOWER = 'lower'; |
|
26
|
|
|
public const LOWER_INCLUSIVE = 'lower_inclusive'; |
|
27
|
|
|
public const GREATER = 'greater'; |
|
28
|
|
|
public const GREATER_INCLUSIVE = 'greater_inclusive'; |
|
29
|
|
|
public const EXACT = 'exact'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public static $defaultTemplates = [ |
|
35
|
|
|
self::MODE_DEFAULT => [ |
|
36
|
|
|
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}', |
|
37
|
|
|
self::LOWER => '{{name}} must have a length greater than {{minValue}}', |
|
38
|
|
|
self::LOWER_INCLUSIVE => '{{name}} must have a length greater than or equal to {{minValue}}', |
|
39
|
|
|
self::GREATER => '{{name}} must have a length lower than {{maxValue}}', |
|
40
|
|
|
self::GREATER_INCLUSIVE => '{{name}} must have a length lower than or equal to {{maxValue}}', |
|
41
|
|
|
self::EXACT => '{{name}} must have a length of {{maxValue}}', |
|
42
|
|
|
], |
|
43
|
|
|
self::MODE_NEGATIVE => [ |
|
44
|
|
|
self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}', |
|
45
|
|
|
self::LOWER => '{{name}} must not have a length greater than {{minValue}}', |
|
46
|
|
|
self::LOWER_INCLUSIVE => '{{name}} must not have a length greater than or equal to {{minValue}}', |
|
47
|
|
|
self::GREATER => '{{name}} must not have a length lower than {{maxValue}}', |
|
48
|
|
|
self::GREATER_INCLUSIVE => '{{name}} must not have a length lower than or equal to {{maxValue}}', |
|
49
|
|
|
self::EXACT => '{{name}} must not have a length of {{maxValue}}', |
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
10 |
|
protected function chooseTemplate(): string |
|
57
|
|
|
{ |
|
58
|
10 |
|
$isInclusive = $this->getParam('inclusive'); |
|
59
|
|
|
|
|
60
|
10 |
|
if (!$this->getParam('minValue')) { |
|
61
|
1 |
|
return $isInclusive === true ? self::GREATER_INCLUSIVE : self::GREATER; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
10 |
|
if (!$this->getParam('maxValue')) { |
|
65
|
1 |
|
return $isInclusive === true ? self::LOWER_INCLUSIVE : self::LOWER; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
10 |
|
if ($this->getParam('minValue') == $this->getParam('maxValue')) { |
|
69
|
|
|
return self::EXACT; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
10 |
|
return self::BOTH; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|