From f678fa9b2b6f2463bbe47e1eed88d94045864077 Mon Sep 17 00:00:00 2001 From: mychidarko Date: Sun, 12 Nov 2023 18:07:39 +0000 Subject: [PATCH] fix: patch up array check --- src/Form.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Form.php b/src/Form.php index af2d7bf..377137f 100644 --- a/src/Form.php +++ b/src/Form.php @@ -115,7 +115,7 @@ public static function test(string $rule, $value, $param = null, $field = null): $rule = $ruleData[0]; if (in_array($rule, static::$specialRules)) { - $params = explode('|', str_replace(['(', ')'], '', $ruleData[1])); + $params = array_filter(explode('|', str_replace(['(', ')'], '', $ruleData[1]))); if ($rule === 'array') { if (!is_array($value)) { @@ -124,10 +124,12 @@ public static function test(string $rule, $value, $param = null, $field = null): $isValid = true; - foreach ($params as $paramValue) { - foreach ($value as $valueArrayItem) { - if (!static::test($paramValue, $valueArrayItem)) { - $isValid = false; + if (count($params) > 0) { + foreach ($params as $paramValue) { + foreach ($value as $valueArrayItem) { + if (!static::test($paramValue, $valueArrayItem)) { + $isValid = false; + } } } }