@@ 10-22 (lines=13) @@ | ||
7 | /** |
|
8 | * Handles 4 digit years supported by mysql 8.0 |
|
9 | */ |
|
10 | class Year implements ValidateRuleInterface |
|
11 | { |
|
12 | public function __invoke($subject, string $field): bool |
|
13 | { |
|
14 | $value = $subject->$field; |
|
15 | ||
16 | if (!is_int($value)) { |
|
17 | return false; |
|
18 | } |
|
19 | ||
20 | return $value >= 1901 && $value <= 2155; |
|
21 | } |
|
22 | } |
|
23 |
@@ 5-24 (lines=20) @@ | ||
2 | ||
3 | namespace Mbright\Validation\Rule\Validate; |
|
4 | ||
5 | class Word implements ValidateRuleInterface |
|
6 | { |
|
7 | /** |
|
8 | * Validates that the value is composed only of word characters (letters,numbers, and underscores). |
|
9 | * |
|
10 | * @param object $subject The subject to be filtered. |
|
11 | * @param string $field The subject field name. |
|
12 | * |
|
13 | * @return bool True if valid, false if not. |
|
14 | */ |
|
15 | public function __invoke($subject, string $field): bool |
|
16 | { |
|
17 | $value = $subject->$field; |
|
18 | if (!is_scalar($value)) { |
|
19 | return false; |
|
20 | } |
|
21 | ||
22 | return (bool) preg_match('/^[\p{L}\p{Nd}_]+$/u', $value); |
|
23 | } |
|
24 | } |
|
25 |