1 | <?php |
||
11 | class Date implements ValidateRuleInterface |
||
12 | { |
||
13 | /** |
||
14 | * Returns a bool indicating if the value can be safely stored in a MySql Date column. |
||
15 | * |
||
16 | * @param object $subject |
||
17 | * @param string $field |
||
18 | * |
||
19 | * @return bool |
||
20 | */ |
||
21 | 36 | public function __invoke($subject, string $field): bool |
|
28 | |||
29 | /** |
||
30 | * Extract date parts from the given string. |
||
31 | * |
||
32 | * Will return a stdClass with 3 properties: year, month, day. Each property defaults to null. If the string cannot |
||
33 | * be parsed, return null. |
||
34 | * |
||
35 | * @param string $dateString |
||
36 | * |
||
37 | * @return null|\stdClass |
||
38 | */ |
||
39 | 36 | protected function extractDateParts(string $dateString): ?\stdClass |
|
60 | |||
61 | /** |
||
62 | * Sanitizes the given dateString to YYYYMMDD. |
||
63 | * |
||
64 | * Returns null if the string cannot be sanitized. |
||
65 | * |
||
66 | * @param string $dateString |
||
67 | * |
||
68 | * @return null|string |
||
69 | */ |
||
70 | 36 | protected function sanitizeDateString(string $dateString): ?string |
|
83 | |||
84 | /** |
||
85 | * Strips delimiters from the given date string and returns the sanitized string. |
||
86 | * |
||
87 | * The returned string will be either |
||
88 | * |
||
89 | * @param string $dateString |
||
90 | * |
||
91 | * @return null|string |
||
92 | */ |
||
93 | 36 | protected function handleDelimiters(string $dateString): ?string |
|
114 | |||
115 | /** |
||
116 | * Converts YYMMDD to YYYYMMDD. |
||
117 | * |
||
118 | * @param string $dateString |
||
119 | * |
||
120 | * @return null|string |
||
121 | */ |
||
122 | 33 | public function normalizeYear(string $dateString): ?string |
|
133 | } |
||
134 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: