|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Smoren\Validator\Factories; |
|
6
|
|
|
|
|
7
|
|
|
use Smoren\Validator\Interfaces\BoolRuleInterface; |
|
8
|
|
|
use Smoren\Validator\Interfaces\RuleInterface; |
|
9
|
|
|
use Smoren\Validator\Interfaces\CompositeRuleInterface; |
|
10
|
|
|
use Smoren\Validator\Interfaces\ContainerRuleInterface; |
|
11
|
|
|
use Smoren\Validator\Interfaces\FloatRuleInterface; |
|
12
|
|
|
use Smoren\Validator\Interfaces\IntegerRuleInterface; |
|
13
|
|
|
use Smoren\Validator\Interfaces\StringRuleInterface; |
|
14
|
|
|
use Smoren\Validator\Rules\AndRule; |
|
15
|
|
|
use Smoren\Validator\Rules\BoolRule; |
|
16
|
|
|
use Smoren\Validator\Rules\ContainerRule; |
|
17
|
|
|
use Smoren\Validator\Rules\FloatRule; |
|
18
|
|
|
use Smoren\Validator\Rules\IntegerRule; |
|
19
|
|
|
use Smoren\Validator\Rules\NumericRule; |
|
20
|
|
|
use Smoren\Validator\Rules\StringRule; |
|
21
|
|
|
use Smoren\Validator\Rules\OrRule; |
|
22
|
|
|
use Smoren\Validator\Structs\RuleName; |
|
23
|
|
|
|
|
24
|
|
|
class Value |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $name |
|
28
|
|
|
* |
|
29
|
|
|
* @return NumericRule |
|
30
|
|
|
*/ |
|
31
|
50 |
|
public static function numeric(string $name = RuleName::NUMERIC): NumericRule |
|
32
|
|
|
{ |
|
33
|
50 |
|
return new NumericRule($name); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $name |
|
38
|
|
|
* |
|
39
|
|
|
* @return IntegerRuleInterface |
|
40
|
|
|
*/ |
|
41
|
62 |
|
public static function integer(string $name = RuleName::INTEGER): IntegerRuleInterface |
|
42
|
|
|
{ |
|
43
|
62 |
|
return new IntegerRule($name); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $name |
|
48
|
|
|
* |
|
49
|
|
|
* @return FloatRuleInterface |
|
50
|
|
|
*/ |
|
51
|
43 |
|
public static function float(string $name = RuleName::FLOAT): FloatRuleInterface |
|
52
|
|
|
{ |
|
53
|
43 |
|
return new FloatRule($name); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $name |
|
58
|
|
|
* |
|
59
|
|
|
* @return BoolRuleInterface |
|
60
|
|
|
*/ |
|
61
|
22 |
|
public static function bool(string $name = RuleName::BOOL): BoolRuleInterface |
|
62
|
|
|
{ |
|
63
|
22 |
|
return new BoolRule($name); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $name |
|
68
|
|
|
* |
|
69
|
|
|
* @return StringRuleInterface |
|
70
|
|
|
*/ |
|
71
|
24 |
|
public static function string(string $name = RuleName::STRING): StringRuleInterface |
|
72
|
|
|
{ |
|
73
|
24 |
|
return new StringRule($name); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $name |
|
78
|
|
|
* |
|
79
|
|
|
* @return ContainerRuleInterface |
|
80
|
|
|
*/ |
|
81
|
49 |
|
public static function container(string $name = RuleName::CONTAINER): ContainerRuleInterface |
|
82
|
|
|
{ |
|
83
|
49 |
|
return new ContainerRule($name); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array<RuleInterface> $rules |
|
88
|
|
|
* @param string $name |
|
89
|
|
|
* |
|
90
|
|
|
* @return CompositeRuleInterface |
|
91
|
|
|
*/ |
|
92
|
9 |
|
public static function or(array $rules, string $name = RuleName::OR): CompositeRuleInterface |
|
93
|
|
|
{ |
|
94
|
9 |
|
return new OrRule($rules, $name); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param array<RuleInterface> $rules |
|
99
|
|
|
* @param string $name |
|
100
|
|
|
* |
|
101
|
|
|
* @return CompositeRuleInterface |
|
102
|
|
|
*/ |
|
103
|
7 |
|
public static function and(array $rules, string $name = RuleName::AND): CompositeRuleInterface |
|
104
|
|
|
{ |
|
105
|
7 |
|
return new AndRule($rules, $name); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|