1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stadly\PasswordPolice\Rule; |
6
|
|
|
|
7
|
|
|
use Stadly\PasswordPolice\Constraint\CountConstraint; |
8
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
9
|
|
|
|
10
|
|
|
final class SymbolRule extends CharacterClassRule |
11
|
|
|
{ |
12
|
5 |
|
protected function getMessage(CountConstraint $constraint, int $count, TranslatorInterface $translator): string |
13
|
|
|
{ |
14
|
5 |
|
if ($constraint->getMax() === null) { |
15
|
1 |
|
return $translator->trans( |
16
|
|
|
'The password must contain at least one symbol (%characters%).|' . |
17
|
1 |
|
'The password must contain at least %count% symbols (%characters%).', |
18
|
|
|
[ |
19
|
1 |
|
'%count%' => $constraint->getMin(), |
20
|
1 |
|
'%characters%' => $this->characters, |
21
|
|
|
] |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
4 |
|
if ($constraint->getMax() === 0) { |
26
|
1 |
|
return $translator->trans( |
27
|
1 |
|
'The password cannot contain symbols (%characters%).', |
28
|
1 |
|
['%characters%' => $this->characters] |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
3 |
|
if ($constraint->getMin() === 0) { |
33
|
1 |
|
return $translator->trans( |
34
|
|
|
'The password must contain at most one symbol (%characters%).|' . |
35
|
1 |
|
'The password must contain at most %count% symbols (%characters%).', |
36
|
|
|
[ |
37
|
1 |
|
'%count%' => $constraint->getMax(), |
38
|
1 |
|
'%characters%' => $this->characters, |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
if ($constraint->getMin() === $constraint->getMax()) { |
44
|
1 |
|
return $translator->trans( |
45
|
|
|
'The password must contain exactly one symbol (%characters%).|' . |
46
|
1 |
|
'The password must contain exactly %count% symbols (%characters%).', |
47
|
|
|
[ |
48
|
1 |
|
'%count%' => $constraint->getMin(), |
49
|
1 |
|
'%characters%' => $this->characters, |
50
|
|
|
] |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
return $translator->trans( |
55
|
1 |
|
'The password must contain between %min% and %max% symbols (%characters%).', |
56
|
|
|
[ |
57
|
1 |
|
'%min%' => $constraint->getMin(), |
58
|
1 |
|
'%max%' => $constraint->getMax(), |
59
|
1 |
|
'%characters%' => $this->characters, |
60
|
|
|
] |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|