This commit is contained in:
2023-04-07 18:23:27 +08:00
parent 6d122c4ae1
commit 5d41c7219f
9 changed files with 339 additions and 328 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ class DefaultCondition extends Condition
*/
#[Pure] public function builder(): string
{
return sprintf('%s %s %s', $this->column, $this->opera, addslashes($this->value));
return $this->column . ' ' . $this->opera . ' ' . addslashes($this->value);
}
}
+4 -5
View File
@@ -12,17 +12,16 @@ class HashCondition extends Condition
/**
* @return string
* @throws \Exception
*/
public function builder(): string
{
$array = [];
if (empty($this->value)) {
return '';
if (count($this->value) < 1) {
throw new \Exception('Builder data by a empty array.');
}
foreach ($this->value as $key => $value) {
if (is_null($value)) continue;
$array[] = sprintf("%s = '%s'", $key, addslashes($value));
$array[] = $key . '=' . addslashes($value);
}
return implode(' AND ', $array);
}
+2 -2
View File
@@ -22,9 +22,9 @@ class InCondition extends Condition
#[Pure] public function builder(): string
{
if (is_array($this->value)) {
return sprintf('%s IN (%s)', $this->column, implode(',', $this->value));
return $this->column . ' IN (' . implode(',', $this->value) . ')';
} else {
return sprintf('%s IN (%s)', $this->column, $this->value);
return $this->column . ' IN (' . $this->value . ')';
}
}
+2 -1
View File
@@ -15,11 +15,12 @@ class NotInCondition extends Condition
/**
* @return string|null
* @throws \Exception
*/
#[Pure] public function builder(): ?string
{
if (!is_array($this->value)) {
return null;
throw new \Exception('Builder data by a empty string. need array');
}
$value = '\'' . implode('\',\'', $this->value) . '\'';
return '`' . $this->column . '` not in(' . $value . ')';
+1 -1
View File
@@ -21,7 +21,7 @@ class OrCondition extends Condition
*/
#[Pure] public function builder(): string
{
return sprintf('(%s) OR %s', implode(' AND ', $this->oldParams), addslashes($this->value));
return '(' . implode(' AND ', $this->oldParams) . ') OR ' . addslashes($this->value);
}
}