44
55namespace PhpMyAdmin\SqlParser;
66
7+ use PhpMyAdmin\SqlParser\Contexts\ContextMySql50700;
8+
79use function class_exists;
810use function explode;
911use function in_array;
@@ -43,27 +45,16 @@ abstract class Context
4345 */
4446 public const OPERATOR_MAX_LENGTH = 4;
4547
46- /**
47- * The name of the default content.
48- *
49- * @var string
50- */
51- public static $defaultContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700';
52-
5348 /**
5449 * The name of the loaded context.
55- *
56- * @var string
5750 */
58- public static $loadedContext = '\\PhpMyAdmin\\SqlParser\\Contexts\\ ContextMySql50700' ;
51+ public static string $loadedContext = ContextMySql50700::class ;
5952
6053 /**
6154 * The prefix concatenated to the context name when an incomplete class name
6255 * is specified.
63- *
64- * @var string
6556 */
66- public static $contextPrefix = '\\ PhpMyAdmin\\SqlParser\\Contexts\\Context';
57+ public static string $contextPrefix = 'PhpMyAdmin\\SqlParser\\Contexts\\Context';
6758
6859 /**
6960 * List of keywords.
@@ -83,14 +74,14 @@ abstract class Context
8374 * @psalm-var non-empty-array<string,Token::FLAG_KEYWORD_*|int>
8475 * @phpstan-var non-empty-array<non-empty-string,Token::FLAG_KEYWORD_*|int>
8576 */
86- public static $keywords = [];
77+ public static array $keywords = [];
8778
8879 /**
8980 * List of operators and their flags.
9081 *
9182 * @var array<string, int>
9283 */
93- public static $operators = [
84+ public static array $operators = [
9485 // Some operators (*, =) may have ambiguous flags, because they depend on
9586 // the context they are being used in.
9687 // For example: 1. SELECT * FROM table; # SQL specific (wildcard)
@@ -144,10 +135,8 @@ abstract class Context
144135 *
145136 * @link https://dev.mysql.com/doc/refman/en/sql-mode.html
146137 * @link https://mariadb.com/kb/en/sql-mode/
147- *
148- * @var int
149138 */
150- public static $mode = self::SQL_MODE_NONE;
139+ public static int $mode = self::SQL_MODE_NONE;
151140
152141 public const SQL_MODE_NONE = 0;
153142
@@ -529,19 +518,19 @@ public static function isSeparator(string $string): bool
529518 */
530519 public static function load(string $context = ''): bool
531520 {
532- if (empty( $context) ) {
533- $context = self::$defaultContext ;
521+ if ($context === '' ) {
522+ $context = ContextMySql50700::class ;
534523 }
535524
536- if ($context[0] !== '\\') {
525+ if (! class_exists($context)) {
526+ if (! class_exists(self::$contextPrefix . $context)) {
527+ return false;
528+ }
529+
537530 // Short context name (must be formatted into class name).
538531 $context = self::$contextPrefix . $context;
539532 }
540533
541- if (! class_exists($context)) {
542- return false;
543- }
544-
545534 self::$loadedContext = $context;
546535 self::$keywords = $context::$keywords;
547536
0 commit comments