File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,11 @@ private function validateWithFormat($value) {
3030 * @return array
3131 */
3232 public function validate ($ value ) {
33- if (!is_string ($ value ) || !is_numeric ($ value )) {
34- return array ("O campo deve ser um valor numérico ou string. " );
35- }
36- if ($ this ->format ) {
37- return $ this ->validateWithFormat ($ value );
33+ if ($ value === null ) {
34+ return array ();
3835 }
3936
40- return strtotime ($ value) === false ? array ( " O campo deve ser uma data valida. " ) : array ( );
37+ return $ this -> validateDateStructure ($ value );
4138 }
4239
4340 /**
@@ -46,4 +43,21 @@ public function validate($value) {
4643 public function setParams ($ params ) {
4744 $ this ->format = isset ($ params [0 ]) && is_string ($ params [0 ]) ? $ params [0 ] : null ;
4845 }
46+
47+ /**
48+ * @param $value
49+ *
50+ * @return array
51+ */
52+ private function validateDateStructure ($ value ) {
53+ if (!is_string ($ value ) || !is_numeric ($ value )) {
54+ return array ("O campo deve ser um valor numérico ou string. " );
55+ }
56+
57+ if ($ this ->format ) {
58+ return $ this ->validateWithFormat ($ value );
59+ }
60+
61+ return strtotime ($ value ) === false ? array ("O campo deve ser uma data valida. " ) : array ();
62+ }
4963}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public function getIdentifier() {
1818 * @return array
1919 */
2020 public function validate ($ value ) {
21- return is_string ($ value ) ? array () : array ("O campo deve ser uma string. " );
21+ return is_string ($ value ) || $ value === null ? array () : array ("O campo deve ser uma string. " );
2222 }
2323
2424 /**
You can’t perform that action at this time.
0 commit comments