From 4176fd77f76404f151b9657ec8ffeaebe0170c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 24 Feb 2021 18:43:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Orm/Condition.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Database/Orm/Condition.php b/Database/Orm/Condition.php index 44c8ee70..debb74fe 100644 --- a/Database/Orm/Condition.php +++ b/Database/Orm/Condition.php @@ -106,16 +106,34 @@ trait Condition return $condition; } foreach ($condition as $key => $value) { - if (empty($value)) continue; - if (!is_numeric($key)) { - $array[] = sprintf('%s=%s', $key, $value); - } else if (is_array($value)) { - $array = $this->_arrayMap($value, $array); - } else { - $array[] = sprintf('%s', $value); - } + $array = $this->resolve($array, $key, $value); } - return implode(' AND ', $array); + if (is_array($array)) { + return implode(' AND ', $array); + } + return $array; + } + + + /** + * @param $array + * @param $key + * @param $value + * @return mixed + * @throws NotFindClassException + * @throws ReflectionException + */ + private function resolve($array, $key, $value): mixed + { + if (empty($value)) return $array; + if (!is_numeric($key)) { + $array[] = sprintf('%s=%s', $key, $value); + } else if (is_array($value)) { + $array = $this->_arrayMap($value, $array); + } else { + $array[] = sprintf('%s', $value); + } + return $array; } @@ -128,7 +146,6 @@ trait Condition */ private function _arrayMap($condition, $array): string { - var_dump($condition); if (!isset($condition[0])) { return implode(' AND ', $this->_hashMap($condition)); }