* Update sqlparser to fit php8.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Parses an array.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Components;
|
||||
|
||||
@@ -11,51 +9,52 @@ 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.
|
||||
*
|
||||
* @category Components
|
||||
*
|
||||
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
|
||||
* @final
|
||||
*/
|
||||
class ArrayObj extends Component
|
||||
{
|
||||
/**
|
||||
* The array that contains the unprocessed value of each token.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
public $raw = array();
|
||||
public $raw = [];
|
||||
|
||||
/**
|
||||
* The array that contains the processed value of each token.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
public $values = array();
|
||||
public $values = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $raw the unprocessed values
|
||||
* @param array $values the processed values
|
||||
* @param string[] $raw the unprocessed values
|
||||
* @param string[] $values the processed values
|
||||
*/
|
||||
public function __construct(array $raw = array(), array $values = array())
|
||||
public function __construct(array $raw = [], array $values = [])
|
||||
{
|
||||
$this->raw = $raw;
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Parser $parser the parser that serves as context
|
||||
* @param TokensList $list the list of tokens that are being parsed
|
||||
* @param array $options parameters for parsing
|
||||
* @param Parser $parser the parser that serves as context
|
||||
* @param TokensList $list the list of tokens that are being parsed
|
||||
* @param array<string, mixed> $options parameters for parsing
|
||||
*
|
||||
* @return ArrayObj|Component[]
|
||||
*/
|
||||
public static function parse(Parser $parser, TokensList $list, array $options = array())
|
||||
public static function parse(Parser $parser, TokensList $list, array $options = [])
|
||||
{
|
||||
$ret = empty($options['type']) ? new self() : array();
|
||||
$ret = empty($options['type']) ? new static() : [];
|
||||
|
||||
/**
|
||||
* The last raw expression.
|
||||
@@ -88,29 +87,26 @@ class ArrayObj extends Component
|
||||
for (; $list->idx < $list->count; ++$list->idx) {
|
||||
/**
|
||||
* Token parsed at this moment.
|
||||
*
|
||||
* @var Token
|
||||
*/
|
||||
$token = $list->tokens[$list->idx];
|
||||
|
||||
// End of statement.
|
||||
if ($token->type === Token::TYPE_DELIMITER) {
|
||||
if ($brackets > 0) {
|
||||
$parser->error('A closing bracket was expected.', $token);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -132,8 +128,9 @@ class ArrayObj extends Component
|
||||
$ret->values[] = trim($lastValue);
|
||||
$lastRaw = $lastValue = '';
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +141,7 @@ class ArrayObj extends Component
|
||||
$ret[] = $options['type']::parse(
|
||||
$parser,
|
||||
$list,
|
||||
empty($options['typeOptions']) ? array() : $options['typeOptions']
|
||||
empty($options['typeOptions']) ? [] : $options['typeOptions']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -153,16 +150,13 @@ class ArrayObj extends Component
|
||||
//
|
||||
// This is treated differently to treat the following cases:
|
||||
//
|
||||
// => array()
|
||||
// (,) => array('', '')
|
||||
// () => array()
|
||||
// (a,) => array('a', '')
|
||||
// (a) => array('a')
|
||||
//
|
||||
// => []
|
||||
// [,] => ['', '']
|
||||
// [] => []
|
||||
// [a,] => ['a', '']
|
||||
// [a] => ['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,16 +165,18 @@ class ArrayObj extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObj|ArrayObj[] $component the component to be built
|
||||
* @param array $options parameters for building
|
||||
* @param ArrayObj|ArrayObj[] $component the component to be built
|
||||
* @param array<string, mixed> $options parameters for building
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function build($component, array $options = array())
|
||||
public static function build($component, array $options = [])
|
||||
{
|
||||
if (is_array($component)) {
|
||||
return implode(', ', $component);
|
||||
} elseif (! empty($component->raw)) {
|
||||
}
|
||||
|
||||
if (! empty($component->raw)) {
|
||||
return '(' . implode(', ', $component->raw) . ')';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user