* Support php 5.3 for sql parser lib.

This commit is contained in:
qixinzhi
2023-02-10 11:24:24 +08:00
parent 7c2e937eda
commit 7c122a0b29
648 changed files with 13815 additions and 279048 deletions
@@ -1,10 +1,9 @@
<?php
/**
* Parses an array.
*/
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Components;
use PhpMyAdmin\SqlParser\Component;
@@ -12,15 +11,12 @@ use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;
use function implode;
use function is_array;
use function strlen;
use function trim;
/**
* Parses an array.
*
* @final
* @category Components
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class ArrayObj extends Component
{
@@ -29,20 +25,22 @@ class ArrayObj extends Component
*
* @var array
*/
public $raw = [];
public $raw = array();
/**
* The array that contains the processed value of each token.
*
* @var array
*/
public $values = [];
public $values = array();
/**
* Constructor.
*
* @param array $raw the unprocessed values
* @param array $values the processed values
*/
public function __construct(array $raw = [], array $values = [])
public function __construct(array $raw = array(), array $values = array())
{
$this->raw = $raw;
$this->values = $values;
@@ -55,9 +53,9 @@ class ArrayObj extends Component
*
* @return ArrayObj|Component[]
*/
public static function parse(Parser $parser, TokensList $list, array $options = [])
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
$ret = empty($options['type']) ? new static() : [];
$ret = empty($options['type']) ? new self() : array();
/**
* The last raw expression.
@@ -101,13 +99,18 @@ class ArrayObj extends Component
}
// Skipping whitespaces and comments.
if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {
if (($token->type === Token::TYPE_WHITESPACE)
|| ($token->type === Token::TYPE_COMMENT)
) {
$lastRaw .= $token->token;
$lastValue = trim($lastValue) . ' ';
continue;
}
if (($brackets === 0) && (($token->type !== Token::TYPE_OPERATOR) || ($token->value !== '('))) {
if (($brackets === 0)
&& (($token->type !== Token::TYPE_OPERATOR)
|| ($token->value !== '('))
) {
$parser->error('An opening bracket was expected.', $token);
break;
}
@@ -130,7 +133,6 @@ class ArrayObj extends Component
$lastRaw = $lastValue = '';
}
}
continue;
}
}
@@ -142,7 +144,7 @@ class ArrayObj extends Component
$ret[] = $options['type']::parse(
$parser,
$list,
empty($options['typeOptions']) ? [] : $options['typeOptions']
empty($options['typeOptions']) ? array() : $options['typeOptions']
);
}
}
@@ -151,13 +153,16 @@ class ArrayObj extends Component
//
// This is treated differently to treat the following cases:
//
// => []
// [,] => ['', '']
// [] => []
// [a,] => ['a', '']
// [a] => ['a']
// => array()
// (,) => array('', '')
// () => array()
// (a,) => array('a', '')
// (a) => array('a')
//
$lastRaw = trim($lastRaw);
if (empty($options['type']) && ((strlen($lastRaw) > 0) || ($isCommaLast))) {
if ((empty($options['type']))
&& ((strlen($lastRaw) > 0) || ($isCommaLast))
) {
$ret->raw[] = $lastRaw;
$ret->values[] = trim($lastValue);
}
@@ -171,13 +176,11 @@ class ArrayObj extends Component
*
* @return string
*/
public static function build($component, array $options = [])
public static function build($component, array $options = array())
{
if (is_array($component)) {
return implode(', ', $component);
}
if (! empty($component->raw)) {
} elseif (! empty($component->raw)) {
return '(' . implode(', ', $component->raw) . ')';
}