This commit is contained in:
2022-01-09 03:49:51 +08:00
parent a45d71d760
commit 2109ed7667
55 changed files with 7278 additions and 7278 deletions
+23 -23
View File
@@ -1,23 +1,23 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class BetweenCondition
* @package Database\Condition
*/
class BetweenCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' BETWEEN ' . (int)$this->value[0] . ' AND ' . (int)$this->value[1];
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class BetweenCondition
* @package Database\Condition
*/
class BetweenCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' BETWEEN ' . (int)$this->value[0] . ' AND ' . (int)$this->value[1];
}
}
+22 -22
View File
@@ -1,22 +1,22 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class ChildCondition
* @package Database\Condition
*/
class ChildCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' ' . $this->opera . ' (' . $this->value . ')';
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class ChildCondition
* @package Database\Condition
*/
class ChildCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' ' . $this->opera . ' (' . $this->value . ')';
}
}
+82 -82
View File
@@ -1,82 +1,82 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component;
/**
* Class Condition
* @package Database\Condition
*/
abstract class Condition extends Component
{
protected string $column = '';
protected string $opera = '=';
/** @var array|mixed */
protected $value;
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
protected array $attributes = [];
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
* @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);
}
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component;
/**
* Class Condition
* @package Database\Condition
*/
abstract class Condition extends Component
{
protected string $column = '';
protected string $opera = '=';
/** @var array|mixed */
protected $value;
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
protected array $attributes = [];
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
* @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);
}
}
}
+24 -24
View File
@@ -1,24 +1,24 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class DefaultCondition
* @package Database\Condition
*/
class DefaultCondition extends Condition
{
/**
* @return string
*/
#[Pure] public function builder(): string
{
return sprintf('%s %s %s', $this->column, $this->opera, addslashes($this->value));
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class DefaultCondition
* @package Database\Condition
*/
class DefaultCondition extends Condition
{
/**
* @return string
*/
#[Pure] public function builder(): string
{
return sprintf('%s %s %s', $this->column, $this->opera, addslashes($this->value));
}
}
+30 -30
View File
@@ -1,30 +1,30 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class HashCondition
* @package Yoc\db\condition
*/
class HashCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
$array = [];
if (empty($this->value)) {
return '';
}
foreach ($this->value as $key => $value) {
if (is_null($value)) continue;
$array[] = sprintf("%s = '%s'", $key, addslashes($value));
}
return implode(' AND ', $array);
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class HashCondition
* @package Yoc\db\condition
*/
class HashCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
$array = [];
if (empty($this->value)) {
return '';
}
foreach ($this->value as $key => $value) {
if (is_null($value)) continue;
$array[] = sprintf("%s = '%s'", $key, addslashes($value));
}
return implode(' AND ', $array);
}
}
+31 -31
View File
@@ -1,31 +1,31 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use Database\ActiveQuery;
use Exception;
use JetBrains\PhpStorm\Pure;
/**
* Class InCondition
* @package Database\Condition
*/
class InCondition extends Condition
{
/**
* @return string
* @throws Exception
*/
#[Pure] public function builder(): string
{
if (is_array($this->value)) {
return sprintf('%s IN (%s)', $this->column, implode(',', $this->value));
} else {
return sprintf('%s IN (%s)', $this->column, $this->value);
}
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use Database\ActiveQuery;
use Exception;
use JetBrains\PhpStorm\Pure;
/**
* Class InCondition
* @package Database\Condition
*/
class InCondition extends Condition
{
/**
* @return string
* @throws Exception
*/
#[Pure] public function builder(): string
{
if (is_array($this->value)) {
return sprintf('%s IN (%s)', $this->column, implode(',', $this->value));
} else {
return sprintf('%s IN (%s)', $this->column, $this->value);
}
}
}
+20 -20
View File
@@ -1,20 +1,20 @@
<?php
namespace Database\Condition;
/**
* Class JsonCondition
* @package Database\Condition
*/
class JsonCondition extends Condition
{
public function builder()
{
// TODO: Implement builder() method.
}
}
<?php
namespace Database\Condition;
/**
* Class JsonCondition
* @package Database\Condition
*/
class JsonCondition extends Condition
{
public function builder()
{
// TODO: Implement builder() method.
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LLikeCondition
* @package Database\Condition
*/
class LLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' LIKE \'%' . addslashes($this->value) . '\'';
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LLikeCondition
* @package Database\Condition
*/
class LLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' LIKE \'%' . addslashes($this->value) . '\'';
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LikeCondition
* @package Database\Condition
*/
class LikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' LIKE \'%' . addslashes($this->value) . '%\'';
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class LikeCondition
* @package Database\Condition
*/
class LikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' LIKE \'%' . addslashes($this->value) . '%\'';
}
}
+78 -78
View File
@@ -1,78 +1,78 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class MathematicsCondition
* @package Database\Condition
*/
class MathematicsCondition extends Condition
{
public string $type = '';
/**
* @return mixed
*/
public function builder(): mixed
{
return $this->{strtolower($this->type)}((float)$this->value);
}
/**
* @param $value
* @return string
*/
public function eq($value): string
{
return $this->column . ' = ' . $value;
}
/**
* @param $value
* @return string
*/
public function neq($value): string
{
return $this->column . ' <> ' . $value;
}
/**
* @param $value
* @return string
*/
public function gt($value): string
{
return $this->column . ' > ' . $value;
}
/**
* @param $value
* @return string
*/
public function egt($value): string
{
return $this->column . ' >= ' . $value;
}
/**
* @param $value
* @return string
*/
public function lt($value): string
{
return $this->column . ' < ' . $value;
}
/**
* @param $value
* @return string
*/
public function elt($value): string
{
return $this->column . ' <= ' . $value;
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class MathematicsCondition
* @package Database\Condition
*/
class MathematicsCondition extends Condition
{
public string $type = '';
/**
* @return mixed
*/
public function builder(): mixed
{
return $this->{strtolower($this->type)}((float)$this->value);
}
/**
* @param $value
* @return string
*/
public function eq($value): string
{
return $this->column . ' = ' . $value;
}
/**
* @param $value
* @return string
*/
public function neq($value): string
{
return $this->column . ' <> ' . $value;
}
/**
* @param $value
* @return string
*/
public function gt($value): string
{
return $this->column . ' > ' . $value;
}
/**
* @param $value
* @return string
*/
public function egt($value): string
{
return $this->column . ' >= ' . $value;
}
/**
* @param $value
* @return string
*/
public function lt($value): string
{
return $this->column . ' < ' . $value;
}
/**
* @param $value
* @return string
*/
public function elt($value): string
{
return $this->column . ' <= ' . $value;
}
}
+22 -22
View File
@@ -1,22 +1,22 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class NotBetweenCondition
* @package Database\Condition
*/
class NotBetweenCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' NOT BETWEEN ' . (int)$this->value[0] . ' AND ' . (int)$this->value[1];
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
/**
* Class NotBetweenCondition
* @package Database\Condition
*/
class NotBetweenCondition extends Condition
{
/**
* @return string
*/
public function builder(): string
{
return $this->column . ' NOT BETWEEN ' . (int)$this->value[0] . ' AND ' . (int)$this->value[1];
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class NotInCondition
* @package Database\Condition
*/
class NotInCondition extends Condition
{
/**
* @return string|null
*/
#[Pure] public function builder(): ?string
{
if (!is_array($this->value)) {
return null;
}
$value = '\'' . implode('\',\'', $this->value) . '\'';
return '`' . $this->column . '` not in(' . $value . ')';
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class NotInCondition
* @package Database\Condition
*/
class NotInCondition extends Condition
{
/**
* @return string|null
*/
#[Pure] public function builder(): ?string
{
if (!is_array($this->value)) {
return null;
}
$value = '\'' . implode('\',\'', $this->value) . '\'';
return '`' . $this->column . '` not in(' . $value . ')';
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class NotLikeCondition
* @package Database\Condition
*/
class NotLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' NOT LIKE \'%' . addslashes($this->value) . '%\'';
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class NotLikeCondition
* @package Database\Condition
*/
class NotLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return $this->column . ' NOT LIKE \'%' . addslashes($this->value) . '%\'';
}
}
+27 -27
View File
@@ -1,27 +1,27 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class OrCondition
* @package Database\Condition
*/
class OrCondition extends Condition
{
public array $oldParams = [];
/**
* @return string
*/
#[Pure] public function builder(): string
{
return sprintf('(%s) OR %s', implode(' AND ', $this->oldParams), addslashes($this->value));
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use JetBrains\PhpStorm\Pure;
/**
* Class OrCondition
* @package Database\Condition
*/
class OrCondition extends Condition
{
public array $oldParams = [];
/**
* @return string
*/
#[Pure] public function builder(): string
{
return sprintf('(%s) OR %s', implode(' AND ', $this->oldParams), addslashes($this->value));
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class RLikeCondition
* @package Database\Condition
*/
class RLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return sprintf('%s LIKE \'%s\'', $this->column, addslashes($this->value));
}
}
<?php
declare(strict_types=1);
namespace Database\Condition;
use Kiri\Core\Str;
/**
* Class RLikeCondition
* @package Database\Condition
*/
class RLikeCondition extends Condition
{
public string $pos = '';
/**
* @return string
*/
public function builder(): string
{
if (!is_string($this->value)) {
$this->value = array_shift($this->value);
}
return sprintf('%s LIKE \'%s\'', $this->column, addslashes($this->value));
}
}