eee
This commit is contained in:
+51
-56
@@ -14,69 +14,64 @@ use Kiri\Abstracts\Component;
|
||||
abstract class Condition extends Component
|
||||
{
|
||||
|
||||
protected string $column = '';
|
||||
protected string $opera = '=';
|
||||
protected string $column = '';
|
||||
protected string $opera = '=';
|
||||
protected mixed $value;
|
||||
protected array $attributes = [];
|
||||
|
||||
/** @var array|mixed */
|
||||
protected mixed $value;
|
||||
abstract public function builder();
|
||||
|
||||
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
|
||||
/**
|
||||
* @param string $column
|
||||
*/
|
||||
public function setColumn(string $column): void
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
protected array $attributes = [];
|
||||
/**
|
||||
* @param string $opera
|
||||
*/
|
||||
public function setOpera(string $opera): void
|
||||
{
|
||||
$this->opera = $opera;
|
||||
}
|
||||
|
||||
abstract public function builder();
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*/
|
||||
public function setColumn(string $column): void
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $opera
|
||||
*/
|
||||
public function setOpera(string $opera): void
|
||||
{
|
||||
$this->opera = $opera;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
*/
|
||||
public function setValue($params): void
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$values = [];
|
||||
foreach ($params as $item => $value) {
|
||||
$values[$item] = is_numeric($value) ? $value : '\'' . $value . '\'';
|
||||
}
|
||||
$this->value = $values;
|
||||
} else {
|
||||
$this->value = $this->checkIsSqlString($params);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $params
|
||||
*/
|
||||
public function setValue($params): void
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$values = [];
|
||||
foreach ($params as $item => $value) {
|
||||
$values[$item] = is_numeric($value) ? $value : '\'' . $value . '\'';
|
||||
}
|
||||
$this->value = $values;
|
||||
} else {
|
||||
$this->value = $this->checkIsSqlString($params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return int|string
|
||||
*/
|
||||
#[Pure] private function checkIsSqlString($params): int|string
|
||||
{
|
||||
if (is_numeric($params)) {
|
||||
return $params;
|
||||
}
|
||||
/**
|
||||
* @param $params
|
||||
* @return int|string
|
||||
*/
|
||||
#[Pure] private function checkIsSqlString($params): int|string
|
||||
{
|
||||
if (is_numeric($params)) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
$check = ltrim($params, '(');
|
||||
$check = strtolower(substr($check, 0, 6));
|
||||
if (in_array($check, ['update', 'select', 'insert', 'delete'])) {
|
||||
return $params;
|
||||
} else {
|
||||
return sprintf('\'%s\'', $params);
|
||||
}
|
||||
}
|
||||
$check = ltrim($params, '(');
|
||||
$check = strtolower(substr($check, 0, 6));
|
||||
if (in_array($check, ['update', 'select', 'insert', 'delete'])) {
|
||||
return $params;
|
||||
} else {
|
||||
return sprintf('\'%s\'', $params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user