From 9f2586ff52a407e21c8a7b05eb8fb94c2e41fb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 4 Jan 2022 15:32:03 -0300 Subject: [PATCH] Remove Context::load call from the Context file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpcs.xml.dist | 4 ---- src/Context.php | 3 --- src/Core.php | 9 +++++++++ src/Lexer.php | 2 ++ src/Parser.php | 2 ++ src/Utils/CLI.php | 5 +++++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2da8ca23f..68a5105e9 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -34,10 +34,6 @@ src/Contexts/* - - src/Context.php - - src/TokensList.php src/UtfString.php diff --git a/src/Context.php b/src/Context.php index 524fa15c0..827d0266a 100644 --- a/src/Context.php +++ b/src/Context.php @@ -639,6 +639,3 @@ public static function hasMode($flag = null) return (self::$MODE & $flag) === $flag; } } - -// Initializing the default context. -Context::load(); diff --git a/src/Core.php b/src/Core.php index ba3654434..b3197a7ce 100644 --- a/src/Core.php +++ b/src/Core.php @@ -33,6 +33,15 @@ class Core */ public $errors = []; + public function __construct() + { + if (Context::$KEYWORDS !== []) { + return; + } + + Context::load(); + } + /** * Creates a new error log. * diff --git a/src/Lexer.php b/src/Lexer.php index fb7320dab..d6ea661ca 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -171,6 +171,8 @@ public static function getTokens($str, $strict = false, $delimiter = null) */ public function __construct($str, $strict = false, $delimiter = null) { + parent::__construct(); + // `strlen` is used instead of `mb_strlen` because the lexer needs to // parse each byte of the input. $len = $str instanceof UtfString ? $str->length() : strlen($str); diff --git a/src/Parser.php b/src/Parser.php index 4547136e7..e40e2e0e0 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -362,6 +362,8 @@ class Parser extends Core */ public function __construct($list = null, $strict = false) { + parent::__construct(); + if (is_string($list) || ($list instanceof UtfString)) { $lexer = new Lexer($list, $strict); $this->list = $lexer->list; diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 744656348..94c3a737a 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -27,6 +27,11 @@ */ class CLI { + public function __construct() + { + Context::load(); + } + /** * @param string[]|false[] $params * @param string[] $longopts