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\MixedRuleInterface; |
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\MixedRule; |
20
|
|
|
use Smoren\Validator\Rules\NumericRule; |
21
|
|
|
use Smoren\Validator\Rules\StringRule; |
22
|
|
|
use Smoren\Validator\Rules\OrRule; |
23
|
|
|
use Smoren\Validator\Structs\RuleName; |
24
|
|
|
|
25
|
|
|
class Value |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param string $name |
29
|
|
|
* |
30
|
|
|
* @return NumericRule |
31
|
|
|
*/ |
32
|
50 |
|
public static function numeric(string $name = RuleName::NUMERIC): NumericRule |
33
|
|
|
{ |
34
|
50 |
|
return new NumericRule($name); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $name |
39
|
|
|
* |
40
|
|
|
* @return IntegerRuleInterface |
41
|
|
|
*/ |
42
|
63 |
|
public static function integer(string $name = RuleName::INTEGER): IntegerRuleInterface |
43
|
|
|
{ |
44
|
63 |
|
return new IntegerRule($name); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $name |
49
|
|
|
* |
50
|
|
|
* @return FloatRuleInterface |
51
|
|
|
*/ |
52
|
44 |
|
public static function float(string $name = RuleName::FLOAT): FloatRuleInterface |
53
|
|
|
{ |
54
|
44 |
|
return new FloatRule($name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $name |
59
|
|
|
* |
60
|
|
|
* @return BoolRuleInterface |
61
|
|
|
*/ |
62
|
22 |
|
public static function bool(string $name = RuleName::BOOL): BoolRuleInterface |
63
|
|
|
{ |
64
|
22 |
|
return new BoolRule($name); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $name |
69
|
|
|
* |
70
|
|
|
* @return StringRuleInterface |
71
|
|
|
*/ |
72
|
24 |
|
public static function string(string $name = RuleName::STRING): StringRuleInterface |
73
|
|
|
{ |
74
|
24 |
|
return new StringRule($name); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $name |
79
|
|
|
* |
80
|
|
|
* @return ContainerRuleInterface |
81
|
|
|
*/ |
82
|
50 |
|
public static function container(string $name = RuleName::CONTAINER): ContainerRuleInterface |
83
|
|
|
{ |
84
|
50 |
|
return new ContainerRule($name); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $name |
89
|
|
|
* |
90
|
|
|
* @return MixedRuleInterface |
91
|
|
|
*/ |
92
|
19 |
|
public static function mixed(string $name = RuleName::CONTAINER): MixedRuleInterface |
93
|
|
|
{ |
94
|
19 |
|
return new MixedRule($name); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param array<MixedRuleInterface> $rules |
99
|
|
|
* @param string $name |
100
|
|
|
* |
101
|
|
|
* @return CompositeRuleInterface |
102
|
|
|
*/ |
103
|
9 |
|
public static function or(array $rules, string $name = RuleName::OR): CompositeRuleInterface |
104
|
|
|
{ |
105
|
9 |
|
return new OrRule($rules, $name); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param array<MixedRuleInterface> $rules |
110
|
|
|
* @param string $name |
111
|
|
|
* |
112
|
|
|
* @return CompositeRuleInterface |
113
|
|
|
*/ |
114
|
7 |
|
public static function and(array $rules, string $name = RuleName::AND): CompositeRuleInterface |
115
|
|
|
{ |
116
|
7 |
|
return new AndRule($rules, $name); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|