* Support php 5.3 for sql parser lib.
This commit is contained in:
+25
-20
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Token utilities.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Utils;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Lexer;
|
||||
use PhpMyAdmin\SqlParser\Token;
|
||||
use PhpMyAdmin\SqlParser\TokensList;
|
||||
use PhpMyAdmin\SqlParser\UtfString;
|
||||
|
||||
use function count;
|
||||
use function strcasecmp;
|
||||
|
||||
/**
|
||||
* Token utilities.
|
||||
*
|
||||
* @category Token
|
||||
*
|
||||
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
|
||||
*/
|
||||
class Tokens
|
||||
{
|
||||
@@ -31,36 +30,42 @@ class Tokens
|
||||
public static function match(Token $token, array $pattern)
|
||||
{
|
||||
// Token.
|
||||
if (isset($pattern['token']) && ($pattern['token'] !== $token->token)) {
|
||||
if (isset($pattern['token'])
|
||||
&& ($pattern['token'] !== $token->token)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Value.
|
||||
if (isset($pattern['value']) && ($pattern['value'] !== $token->value)) {
|
||||
if (isset($pattern['value'])
|
||||
&& ($pattern['value'] !== $token->value)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($pattern['value_str']) && strcasecmp($pattern['value_str'], (string) $token->value)) {
|
||||
if (isset($pattern['value_str'])
|
||||
&& strcasecmp($pattern['value_str'], $token->value)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Type.
|
||||
if (isset($pattern['type']) && ($pattern['type'] !== $token->type)) {
|
||||
if (isset($pattern['type'])
|
||||
&& ($pattern['type'] !== $token->type)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Flags.
|
||||
return ! isset($pattern['flags'])
|
||||
|| (! (($pattern['flags'] & $token->flags) === 0));
|
||||
if (isset($pattern['flags'])
|
||||
&& (($pattern['flags'] & $token->flags) === 0)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TokensList|string|UtfString $list
|
||||
* @param array $find
|
||||
* @param array $replace
|
||||
*
|
||||
* @return TokensList
|
||||
*/
|
||||
public static function replaceTokens($list, array $find, array $replace)
|
||||
{
|
||||
/**
|
||||
@@ -80,7 +85,7 @@ class Tokens
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
$newList = [];
|
||||
$newList = array();
|
||||
|
||||
/**
|
||||
* The length of the find pattern is calculated only once.
|
||||
|
||||
Reference in New Issue
Block a user