Files
kiri-core/Database/Condition/Condition.php
T

59 lines
1.1 KiB
PHP
Raw Normal View History

2020-08-31 12:38:32 +08:00
<?php
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-08-31 12:38:32 +08:00
namespace Database\Condition;
use Snowflake\Abstracts\BaseObject;
use Snowflake\Core\Str;
/**
* Class Condition
* @package Database\Condition
*/
abstract class Condition extends BaseObject
{
2020-10-29 18:17:25 +08:00
protected string $column = '';
protected string $opera = '=';
2020-08-31 12:38:32 +08:00
/** @var array|mixed */
protected $value;
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
2020-10-29 18:17:25 +08:00
protected array $attributes = [];
2020-08-31 12:38:32 +08:00
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 $value
*/
public function setValue($value): void
{
2021-02-26 11:03:57 +08:00
$this->value = is_numeric($value) ? $value : '\'' . $value . '\'';
if (is_array($this->value)) {
$this->value = array_map(function ($value) {
return is_numeric($value) ? $value : '\''.$value.'\'';
}, $this->value);
2020-08-31 12:38:32 +08:00
}
}
}