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