-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRule.php
More file actions
executable file
·150 lines (130 loc) · 3.66 KB
/
Copy pathRule.php
File metadata and controls
executable file
·150 lines (130 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Validation;
use Closure;
use Hyperf\Contract\Arrayable;
use Hyperf\Macroable\Macroable;
use Hyperf\Validation\Contract\Rule as RuleContract;
use Hyperf\Validation\Rules\ArrayRule;
use Hyperf\Validation\Rules\Enum;
use Hyperf\Validation\Rules\ExcludeIf;
use Hyperf\Validation\Rules\File;
use Hyperf\Validation\Rules\ImageFile;
use Hyperf\Validation\Rules\ProhibitedIf;
class Rule
{
use Macroable;
/**
* Get a dimensions constraint builder instance.
*/
public static function dimensions(array $constraints = []): Rules\Dimensions
{
return new Rules\Dimensions($constraints);
}
/**
* Get a exists constraint builder instance.
*/
public static function exists(string $table, string $column = 'NULL'): Rules\Exists
{
return new Rules\Exists($table, $column);
}
/**
* Get an in constraint builder instance.
*/
public static function in(mixed $values): Rules\In
{
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
return new Rules\In(is_array($values) ? $values : func_get_args());
}
/**
* Get a not_in constraint builder instance.
*/
public static function notIn(mixed $values): Rules\NotIn
{
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
return new Rules\NotIn(is_array($values) ? $values : func_get_args());
}
/**
* Get a required_if constraint builder instance.
*/
public static function requiredIf(bool|callable $callback): Rules\RequiredIf
{
return new Rules\RequiredIf($callback);
}
/**
* Get a unique constraint builder instance.
*/
public static function unique(string $table, string $column = 'NULL'): Rules\Unique
{
return new Rules\Unique($table, $column);
}
public static function prohibitedIf($callback): ProhibitedIf
{
return new ProhibitedIf($callback);
}
public static function excludeIf($callback): ExcludeIf
{
return new ExcludeIf($callback);
}
/**
* Apply the given rules if the given condition is truthy.
*/
public static function when(
bool|Closure $condition,
array|Closure|RuleContract|string $rules,
array|Closure|RuleContract|string $defaultRules = []
): ConditionalRules {
return new ConditionalRules($condition, $rules, $defaultRules);
}
/**
* Apply the given rules if the given condition is falsy.
*/
public static function unless(
bool|Closure $condition,
array|Closure|RuleContract|string $rules,
array|Closure|RuleContract|string $defaultRules = []
): ConditionalRules {
return new ConditionalRules($condition, $defaultRules, $rules);
}
/**
* Get an array rule builder instance.
* @param null|mixed $keys
*/
public static function array($keys = null): ArrayRule
{
return new ArrayRule(...func_get_args());
}
/**
* Get an enum rule builder instance.
*/
public static function enum(string $type): Enum
{
return new Enum($type);
}
/**
* Get a file rule builder instance.
*/
public static function file(): File
{
return new File();
}
/**
* Get an image file rule builder instance.
*/
public static function imageFile(): File
{
return new ImageFile();
}
}