|
27 | 27 | * |
28 | 28 | * Holds the configuration of the context that is currently used. |
29 | 29 | */ |
30 | | -abstract class Context |
| 30 | +final class Context |
31 | 31 | { |
32 | 32 | /** |
33 | 33 | * The maximum length of a keyword. |
@@ -55,7 +55,7 @@ abstract class Context |
55 | 55 | * The prefix concatenated to the context name when an incomplete class name |
56 | 56 | * is specified. |
57 | 57 | */ |
58 | | - public static string $contextPrefix = 'PhpMyAdmin\\SqlParser\\Contexts\\Context'; |
| 58 | + private const CONTEXT_PREFIX = 'PhpMyAdmin\\SqlParser\\Contexts\\Context'; |
59 | 59 |
|
60 | 60 | /** |
61 | 61 | * List of keywords. |
@@ -486,22 +486,19 @@ public static function load(string $context = ''): bool |
486 | 486 | $context = ContextMySql50700::class; |
487 | 487 | } |
488 | 488 |
|
489 | | - if (! class_exists($context)) { |
490 | | - if (! class_exists(self::$contextPrefix . $context)) { |
491 | | - return false; |
492 | | - } |
493 | | - |
494 | | - // Could be the fully qualified class name was given, like `ContextDBMS::class`. |
495 | | - if (class_exists('\\' . $context)) { |
496 | | - $context = '\\' . $context; |
497 | | - } else { |
498 | | - // Short context name (must be formatted into class name). |
499 | | - $context = self::$contextPrefix . $context; |
| 489 | + $contextClass = $context; |
| 490 | + if (! class_exists($contextClass)) { |
| 491 | + $contextClass = self::CONTEXT_PREFIX . $context; |
| 492 | + if (! class_exists($contextClass)) { |
| 493 | + $contextClass = '\\' . $context; |
| 494 | + if (! class_exists($contextClass)) { |
| 495 | + return false; |
| 496 | + } |
500 | 497 | } |
501 | 498 | } |
502 | 499 |
|
503 | | - self::$loadedContext = $context; |
504 | | - self::$keywords = $context::$keywords; |
| 500 | + self::$loadedContext = $contextClass; |
| 501 | + self::$keywords = $contextClass::KEYWORDS; |
505 | 502 |
|
506 | 503 | return true; |
507 | 504 | } |
|
0 commit comments