From 6d122c4ae15cca9a19048a3d04a494d94ee850d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 7 Apr 2023 18:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Traits/QueryTrait.php | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/Traits/QueryTrait.php b/Traits/QueryTrait.php index 653a404..105bd3a 100644 --- a/Traits/QueryTrait.php +++ b/Traits/QueryTrait.php @@ -794,21 +794,17 @@ trait QueryTrait } /** - * @param Closure|array|string $column + * @param array|string $column * @param string $opera * @param null $value * @return $this * @throws */ - public function where(Closure|array|string $column, string $opera = '=', $value = null): static + public function where(array|string $column, string $opera = '=', $value = null): static { if (is_array($column)) { return $this->addArray($column); } - if ($column instanceof Closure) { - $this->where[] = $this->makeClosureFunction($column); - return $this; - } if (is_string($column)) { $this->where[] = $column; } else { @@ -890,14 +886,7 @@ trait QueryTrait private function addArray(array $array): static { foreach ($array as $key => $value) { - if (is_null($value)) continue; - if (is_numeric($key)) { - [$column, $opera, $value] = $this->opera(...$value); - - $this->where[] = $this->sprintf($column, $value, $opera); - } else { - $this->where[] = $this->sprintf($key, $value); - } + $this->where[] = $this->sprintf($key, $value); } return $this; } @@ -911,11 +900,10 @@ trait QueryTrait */ private function sprintf($column, $value, string $opera = '='): string { - if (is_numeric($value)) { - return "$column $opera $value"; + if (is_string($value)) { + $value = addslashes($value); } - $value = trim($value, '\'"'); - return "$column $opera '$value'"; + return $column . ' ' . $opera . ' \'' . $value . '\''; }