|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Validator\Rule; |
|
6
|
|
|
|
|
7
|
|
|
use Attribute; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
|
|
10
|
|
|
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] |
|
11
|
|
|
final class Number extends AbstractNumber |
|
12
|
|
|
{ |
|
13
|
|
|
public function __construct( |
|
14
|
|
|
float|int|null $min = null, |
|
15
|
|
|
float|int|null $max = null, |
|
16
|
|
|
string $incorrectInputMessage = 'The allowed types are integer, float and string.', |
|
17
|
|
|
string $notNumberMessage = 'Value must be a number.', |
|
18
|
|
|
string $tooSmallMessage = 'Value must be no less than {min}.', |
|
19
|
|
|
string $tooBigMessage = 'Value must be no greater than {max}.', |
|
20
|
|
|
string $pattern = '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
|
21
|
|
|
mixed $skipOnEmpty = null, |
|
22
|
|
|
bool $skipOnError = false, |
|
23
|
|
|
Closure|null $when = null, |
|
24
|
|
|
) { |
|
25
|
|
|
parent::__construct( |
|
26
|
|
|
min: $min, |
|
27
|
|
|
max: $max, |
|
28
|
|
|
incorrectInputMessage: $incorrectInputMessage, |
|
29
|
|
|
notNumberMessage: $notNumberMessage, |
|
30
|
|
|
tooSmallMessage: $tooSmallMessage, |
|
31
|
|
|
tooBigMessage: $tooBigMessage, |
|
32
|
36 |
|
pattern: $pattern, |
|
33
|
|
|
skipOnEmpty: $skipOnEmpty, |
|
34
|
|
|
skipOnError: $skipOnError, |
|
35
|
|
|
when: $when, |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getName(): string |
|
40
|
|
|
{ |
|
41
|
|
|
return 'number'; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|