1 | <?php |
||
20 | class StringAttribute extends GenericAttribute |
||
21 | { |
||
22 | /** |
||
23 | * @param string $propertyName |
||
24 | * @param Validator $validator |
||
25 | * @param array $errorMessages |
||
26 | * @param array $functionMap |
||
27 | */ |
||
28 | public function __construct($propertyName, Validator $validator, array &$errorMessages, array &$functionMap) |
||
34 | |||
35 | /** |
||
36 | * Validates alphanumeric characters from a-Z and 0-9 |
||
37 | * |
||
38 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
39 | */ |
||
40 | public function isAlphanumeric() |
||
46 | |||
47 | /** |
||
48 | * Validates alphanumeric characters from a-Z, white spaces and empty values. |
||
49 | * |
||
50 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
51 | */ |
||
52 | public function isAlpha() |
||
58 | |||
59 | /** |
||
60 | * Validates is a string is between ranges. |
||
61 | * |
||
62 | * @param int $min |
||
63 | * @param int $max |
||
64 | * @param bool $inclusive |
||
65 | * |
||
66 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
67 | */ |
||
68 | public function isBetween($min, $max, $inclusive = false) |
||
74 | |||
75 | /** |
||
76 | * Validates if a string is in a specific charset |
||
77 | * |
||
78 | * @param string[] $charsetNames |
||
79 | * |
||
80 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
81 | */ |
||
82 | public function isCharset(array $charsetNames) |
||
88 | |||
89 | /** |
||
90 | * Validates strings that contain only consonants. |
||
91 | * |
||
92 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
93 | */ |
||
94 | public function isAllConsonants() |
||
100 | |||
101 | /** |
||
102 | * Validates if the input is equal some value. |
||
103 | * |
||
104 | * @param mixed $comparedValue |
||
105 | * @param bool $identical |
||
106 | * |
||
107 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
108 | */ |
||
109 | public function equals($comparedValue, $identical = false) |
||
115 | |||
116 | /** |
||
117 | * @param $value |
||
118 | * @param bool $identical |
||
119 | * |
||
120 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
121 | */ |
||
122 | public function contains($value, $identical = false) |
||
128 | |||
129 | /** |
||
130 | * Only accepts control characters. |
||
131 | * |
||
132 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
133 | */ |
||
134 | public function isControlCharacters() |
||
140 | |||
141 | /** |
||
142 | * Validates a value that doesn't allow a-Z, but accepts empty values and whitespace. |
||
143 | * |
||
144 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
145 | */ |
||
146 | public function isDigit() |
||
152 | |||
153 | /** |
||
154 | * Validates if a given value is at the end of the input. |
||
155 | * |
||
156 | * @param string $word |
||
157 | * @param bool $identical |
||
158 | * |
||
159 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
160 | */ |
||
161 | public function endsWith($word, $identical = false) |
||
167 | |||
168 | /** |
||
169 | * Validates if the input is contained in a specific haystack. |
||
170 | * |
||
171 | * @param string $haystack |
||
172 | * @param bool $identical |
||
173 | * |
||
174 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
175 | */ |
||
176 | public function in($haystack, $identical = false) |
||
182 | |||
183 | /** |
||
184 | * Validates all characters that are graphically represented. |
||
185 | * |
||
186 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
187 | */ |
||
188 | public function hasGraphicalCharsOnly() |
||
194 | |||
195 | /** |
||
196 | * @param integer $length |
||
197 | * |
||
198 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
199 | */ |
||
200 | public function hasLength($length) |
||
206 | |||
207 | /** |
||
208 | * Validates if string characters are lowercase in the input. |
||
209 | * |
||
210 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
211 | */ |
||
212 | public function isLowercase() |
||
218 | |||
219 | /** |
||
220 | * Validates if the given input is not empty or in other words is input mandatory and required. |
||
221 | * This function also takes whitespace into account, use noWhitespace() if no spaces or line breaks |
||
222 | * and other whitespace anywhere in the input is desired |
||
223 | * |
||
224 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
225 | */ |
||
226 | public function notEmpty() |
||
232 | |||
233 | /** |
||
234 | * Validates if a string contains no whitespace (spaces, tabs and line breaks). |
||
235 | * |
||
236 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
237 | */ |
||
238 | public function noWhitespace() |
||
244 | |||
245 | /** |
||
246 | * Validates all characters that are graphically printable. |
||
247 | * |
||
248 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
249 | */ |
||
250 | public function hasPrintableCharsOnly() |
||
256 | |||
257 | /** |
||
258 | * Accepts only punctuation characters. |
||
259 | * |
||
260 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
261 | */ |
||
262 | public function isPunctuation() |
||
268 | |||
269 | /** |
||
270 | * Evaluates a regex on the input and validates if matches. |
||
271 | * |
||
272 | * @param string $regex |
||
273 | * |
||
274 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
275 | */ |
||
276 | public function matchesRegex($regex) |
||
282 | |||
283 | /** |
||
284 | * Validates slug-like strings. |
||
285 | * |
||
286 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
287 | */ |
||
288 | public function isSlug() |
||
294 | |||
295 | /** |
||
296 | * @param |
||
297 | * |
||
298 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
299 | */ |
||
300 | public function isSpace() |
||
306 | |||
307 | /** |
||
308 | * This validator validates only if the value is at the beginning of a string. |
||
309 | * |
||
310 | * @param mixed $word |
||
311 | * @param bool $identical |
||
312 | * |
||
313 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
314 | */ |
||
315 | public function startsWith($word, $identical = false) |
||
321 | |||
322 | /** |
||
323 | * Validates if string characters are uppercase in the input. |
||
324 | * |
||
325 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
326 | */ |
||
327 | public function isUppercase() |
||
333 | |||
334 | /** |
||
335 | * Validates version numbers using Semantic Versioning. Eg: 1.0.0 |
||
336 | * |
||
337 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
338 | */ |
||
339 | public function isVersion() |
||
345 | |||
346 | /** |
||
347 | * Validates strings that contains only vowels. |
||
348 | * |
||
349 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
350 | */ |
||
351 | public function isVowel() |
||
357 | |||
358 | /** |
||
359 | * Accepts an hexadecimal number, however, that it doesn't accept strings starting with 0x. |
||
360 | * |
||
361 | * @return \NilPortugues\Validator\Attribute\String\StringAttribute |
||
362 | */ |
||
363 | public function isHexDigit() |
||
369 | |||
370 | /** |
||
371 | * @param int $amount |
||
372 | * |
||
373 | * @return $this |
||
374 | */ |
||
375 | public function hasLowercase($amount = null) |
||
381 | |||
382 | /** |
||
383 | * @param int $amount |
||
384 | * |
||
385 | * @return $this |
||
386 | */ |
||
387 | public function hasUppercase($amount = null) |
||
393 | |||
394 | /** |
||
395 | * @param int $amount |
||
396 | * |
||
397 | * @return $this |
||
398 | */ |
||
399 | public function hasNumeric($amount = null) |
||
405 | |||
406 | /** |
||
407 | * @param integer $amount |
||
408 | * |
||
409 | * @return $this |
||
410 | */ |
||
411 | public function hasSpecialCharacters($amount = null) |
||
417 | |||
418 | /** |
||
419 | * @return $this |
||
420 | */ |
||
421 | public function isEmail() |
||
427 | |||
428 | /** |
||
429 | * @return $this |
||
430 | */ |
||
431 | public function isUrl() |
||
437 | |||
438 | /** |
||
439 | * @param bool $strict |
||
440 | * |
||
441 | * @return $this |
||
442 | */ |
||
443 | public function isUUID($strict = true) |
||
449 | } |
||
450 |