Skip to content

Commit 1289384

Browse files
committed
Improve validation documentation
1 parent 61ccfcc commit 1289384

File tree

1 file changed

+114
-7
lines changed

1 file changed

+114
-7
lines changed

docs/content/en/validation.md

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,179 @@ position: 2
1515

1616
Checks if the string contains only digits/alphabet/-/_.
1717

18+
```php
19+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\AlphaDashRule()]);
20+
```
21+
1822
### AlphaNumericRule
1923

2024
Checks if the value is valid IP (using [FILTER_VALIDATE_IP](https://www.php.net/manual/en/filter.filters.flags.php))
2125

26+
```php
27+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\AlphaNumericRule()]);
28+
```
29+
2230
### ArrayRule
2331

24-
Checks if the given value is an array. Not needed if using `getArray*` methods.
32+
> Not needed if using `getArray*` methods.
33+
34+
Checks if the given value is an array.
35+
36+
```php
37+
$getValue->getArray('test', rules: [new \Wrkflow\GetValue\Rules\ArrayRule()]);
38+
```
2539

2640
### BetweenRule
2741

2842
> Uses SizeRule
2943
30-
Checks if the array|float|int|bool|string|null is within max/min (int/float).
44+
Checks if value is withing given range:
45+
46+
- array - count of items equals to given value
47+
- float, int - equals to given value
48+
- bool - equals to given value 1 (true) or 0 (false)
49+
- string - length of string equals to given value
50+
51+
```php
52+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\BetweenRule(2, 3)]);
53+
$getValue->getInt('test', rules: [new \Wrkflow\GetValue\Rules\BetweenRule(2, 3)]);
54+
$getValue->getArray('test', rules: [new \Wrkflow\GetValue\Rules\BetweenRule(1, 4)]);
55+
$getValue->getFloat('test', rules: [new \Wrkflow\GetValue\Rules\BetweenRule(1.0, 1.5)]);
56+
```
3157

3258
### BooleanRule
3359

60+
> Not needed while using getBool
61+
3462
Checks if the value is a boolean.
3563

64+
```php
65+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\BooleanRule()]);
66+
```
67+
3668
### EmailRule
3769

38-
Checks if the value is valid e-mail (
39-
using [FILTER_VALIDATE_EMAIL](https://www.php.net/manual/en/filter.filters.flags.php))
70+
Checks if the value is valid e-mail.
71+
Using [FILTER_VALIDATE_EMAIL](https://www.php.net/manual/en/filter.filters.flags.php)
72+
73+
```php
74+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\EmailRule()]);
75+
```
4076

4177
### FloatRule
4278

79+
> Not needed if using `getFloat*` methods.
80+
4381
Checks if the value is a float.
4482

83+
```php
84+
$getValue->getFloat('test', rules: [new \Wrkflow\GetValue\Rules\FloatRule()]);
85+
```
86+
87+
### HexColorRule
88+
89+
Checks if the value is valid HEX color (alphanumeric string with 3 to 6 chars without or with #).
90+
91+
```php
92+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\HexColorRule()]);
93+
```
94+
4595
### IntegerRule
4696

97+
> Not needed if using `getInt*` methods.
98+
4799
Checks if the value is a integer.
48100

101+
```php
102+
$getValue->getInt('test', rules: [new \Wrkflow\GetValue\Rules\IntegerRule()]);
103+
```
104+
49105
### IpRule
50106

51107
Checks if the value is valid IP (using [FILTER_VALIDATE_IP](https://www.php.net/manual/en/filter.filters.flags.php))
52108

109+
```php
110+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\IpRule()]);
111+
```
112+
53113
### MaxRule
54114

55115
> Uses SizeRule
56116
57-
Checks if the array|float|int|bool|string|null is equal or greater than given int/float value.
117+
Checks if value is equal or greater than given int/float value.
118+
119+
- array - count of items equals to given value
120+
- float, int - equals to given value
121+
- bool - equals to given value 1 (true) or 0 (false)
122+
- string - length of string equals to given value
123+
124+
```php
125+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\MaxRule(2)]);
126+
$getValue->getInt('test', rules: [new \Wrkflow\GetValue\Rules\MaxRule(2)]);
127+
$getValue->getArray('test', rules: [new \Wrkflow\GetValue\Rules\MaxRule(1)]);
128+
$getValue->getFloat('test', rules: [new \Wrkflow\GetValue\Rules\MaxRule(1.0)]);
129+
```
58130

59131
### MinRule
60132

61-
Checks if the array|float|int|bool|string|null is equal or lower than given int/float value.
133+
Checks if value is equal or lower than given int/float value.
134+
135+
- array - count of items equals to given value
136+
- float, int - equals to given value
137+
- bool - equals to given value 1 (true) or 0 (false)
138+
- string - length of string equals to given value
139+
140+
```php
141+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\MinRule(2)]);
142+
$getValue->getInt('test', rules: [new \Wrkflow\GetValue\Rules\MinRule(2)]);
143+
$getValue->getArray('test', rules: [new \Wrkflow\GetValue\Rules\MinRule(1)]);
144+
$getValue->getFloat('test', rules: [new \Wrkflow\GetValue\Rules\MinRule(1.0)]);
145+
```
62146

63147
### NumericRule
64148

149+
> Not needed if using `getInt*` methods.
150+
65151
Checks if the value is a numeric.
66152

153+
```php
154+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\NumericRule()]);
155+
```
156+
67157
### RegexRule
68158

69159
Checks if value is valid against given regex.
70160

161+
```php
162+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\RegexRule('/[\d]+/')]);
163+
```
164+
71165
### SizeRule
72166

73-
Checks if:
167+
Checks if value is equal to given float/int value:
74168

75169
- array - count of items equals to given value
76170
- float, int - equals to given value
77171
- bool - equals to given value 1 (true) or 0 (false)
78172
- string - length of string equals to given value
79173

174+
```php
175+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\SizeRule(2)]);
176+
$getValue->getInt('test', rules: [new \Wrkflow\GetValue\Rules\SizeRule(2)]);
177+
$getValue->getArray('test', rules: [new \Wrkflow\GetValue\Rules\SizeRule(1)]);
178+
$getValue->getFloat('test', rules: [new \Wrkflow\GetValue\Rules\SizeRule(1.0)]);
179+
```
180+
80181
### StringRule
81182

183+
> Not needed if using `getString*` methods.
184+
82185
Checks if value is valid string.
83186

187+
```php
188+
$getValue->getString('test', rules: [new \Wrkflow\GetValue\Rules\StringRule()]);
189+
```
190+
84191
### UrlRule
85192

86193
Checks if the value is valid URL (using [FILTER_VALIDATE_URL](https://www.php.net/manual/en/filter.filters.flags.php))

0 commit comments

Comments
 (0)