mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #5262 from kenjis/remove-static-for-php81
Remove static variables for PHP 8.1
This commit is contained in:
commit
4034dc4122
@ -244,6 +244,20 @@ class BaseBuilder
|
||||
'RIGHT OUTER',
|
||||
];
|
||||
|
||||
/**
|
||||
* Strings that determine if a string represents a literal value or a field name
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $isLiteralStr = [];
|
||||
|
||||
/**
|
||||
* RegExp used to get operators
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $pregOperators = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -2515,13 +2529,11 @@ class BaseBuilder
|
||||
return true;
|
||||
}
|
||||
|
||||
static $_str;
|
||||
|
||||
if (empty($_str)) {
|
||||
$_str = ($this->db->escapeChar !== '"') ? ['"', "'"] : ["'"];
|
||||
if ($this->isLiteralStr === []) {
|
||||
$this->isLiteralStr = $this->db->escapeChar !== '"' ? ['"', "'"] : ["'"];
|
||||
}
|
||||
|
||||
return in_array($str[0], $_str, true);
|
||||
return in_array($str[0], $this->isLiteralStr, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2600,7 +2612,10 @@ class BaseBuilder
|
||||
*/
|
||||
protected function hasOperator(string $str): bool
|
||||
{
|
||||
return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str));
|
||||
return preg_match(
|
||||
'/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i',
|
||||
trim($str)
|
||||
) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2610,11 +2625,11 @@ class BaseBuilder
|
||||
*/
|
||||
protected function getOperator(string $str, bool $list = false)
|
||||
{
|
||||
static $_operators;
|
||||
|
||||
if (empty($_operators)) {
|
||||
$_les = ($this->db->likeEscapeStr !== '') ? '\s+' . preg_quote(trim(sprintf($this->db->likeEscapeStr, $this->db->likeEscapeChar)), '/') : '';
|
||||
$_operators = [
|
||||
if ($this->pregOperators === []) {
|
||||
$_les = $this->db->likeEscapeStr !== ''
|
||||
? '\s+' . preg_quote(trim(sprintf($this->db->likeEscapeStr, $this->db->likeEscapeChar)), '/')
|
||||
: '';
|
||||
$this->pregOperators = [
|
||||
'\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
|
||||
'\s*<>?\s*', // <, <>
|
||||
'\s*>\s*', // >
|
||||
@ -2630,7 +2645,11 @@ class BaseBuilder
|
||||
];
|
||||
}
|
||||
|
||||
return preg_match_all('/' . implode('|', $_operators) . '/i', $str, $match) ? ($list ? $match[0] : $match[0][0]) : false;
|
||||
return preg_match_all(
|
||||
'/' . implode('|', $this->pregOperators) . '/i',
|
||||
$str,
|
||||
$match
|
||||
) ? ($list ? $match[0] : $match[0][0]) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,6 +238,13 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public $likeEscapeChar = '!';
|
||||
|
||||
/**
|
||||
* RegExp used to escape identifiers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pregEscapeChar = [];
|
||||
|
||||
/**
|
||||
* Holds previously looked up data
|
||||
* for performance reasons.
|
||||
@ -1119,29 +1126,35 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
return $item;
|
||||
}
|
||||
|
||||
static $pregEc = [];
|
||||
|
||||
if (empty($pregEc)) {
|
||||
if ($this->pregEscapeChar === []) {
|
||||
if (is_array($this->escapeChar)) {
|
||||
$pregEc = [
|
||||
$this->pregEscapeChar = [
|
||||
preg_quote($this->escapeChar[0], '/'),
|
||||
preg_quote($this->escapeChar[1], '/'),
|
||||
$this->escapeChar[0],
|
||||
$this->escapeChar[1],
|
||||
];
|
||||
} else {
|
||||
$pregEc[0] = $pregEc[1] = preg_quote($this->escapeChar, '/');
|
||||
$pregEc[2] = $pregEc[3] = $this->escapeChar;
|
||||
$this->pregEscapeChar[0] = $this->pregEscapeChar[1] = preg_quote($this->escapeChar, '/');
|
||||
$this->pregEscapeChar[2] = $this->pregEscapeChar[3] = $this->escapeChar;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->reservedIdentifiers as $id) {
|
||||
if (strpos($item, '.' . $id) !== false) {
|
||||
return preg_replace('/' . $pregEc[0] . '?([^' . $pregEc[1] . '\.]+)' . $pregEc[1] . '?\./i', $pregEc[2] . '$1' . $pregEc[3] . '.', $item);
|
||||
return preg_replace(
|
||||
'/' . $this->pregEscapeChar[0] . '?([^' . $this->pregEscapeChar[1] . '\.]+)' . $this->pregEscapeChar[1] . '?\./i',
|
||||
$this->pregEscapeChar[2] . '$1' . $this->pregEscapeChar[3] . '.',
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return preg_replace('/' . $pregEc[0] . '?([^' . $pregEc[1] . '\.]+)' . $pregEc[1] . '?(\.)?/i', $pregEc[2] . '$1' . $pregEc[3] . '$2', $item);
|
||||
return preg_replace(
|
||||
'/' . $this->pregEscapeChar[0] . '?([^' . $this->pregEscapeChar[1] . '\.]+)' . $this->pregEscapeChar[1] . '?(\.)?/i',
|
||||
$this->pregEscapeChar[2] . '$1' . $this->pregEscapeChar[3] . '$2',
|
||||
$item
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user