]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 12 Dec 2021 07:44:25 +0000 (08:44 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 12 Dec 2021 07:44:25 +0000 (08:44 +0100)
- "cached" configuration entry 'developer_mode_enabled' and
  'debug_*_output_timings' into class fields to avoid "expensive" calls all over
  again to FrameworkConfiguration->getConfigEntry()

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/loader/class_ClassLoader.php
framework/main/classes/output/debug/console/class_DebugConsoleOutput.php

index 247975faf5640c335da12165346b658cfde27677..8ce8488a5f2b12ef4c88b28fc571e924b61ad5b1 100644 (file)
@@ -66,6 +66,11 @@ final class ClassLoader {
         */
        private static $selfInstance = NULL;
 
+       /**
+        * Cached configuration entry 'developer_mode_enabled'
+        */
+       private static $developerModeEnabled = false;
+
        /**
         * Array with all valid but pending for loading file names (class,
         * interfaces, traits must start with below prefix).
@@ -152,7 +157,8 @@ final class ClassLoader {
         * @return      void
         */
        private function __construct () {
-               // This is empty for now
+               // Cache config entry
+               self::$developerModeEnabled = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled');
        }
 
        /**
@@ -162,7 +168,7 @@ final class ClassLoader {
         */
        public function __destruct () {
                // Skip here if dev-mode
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
+               if (self::$developerModeEnabled) {
                        return;
                }
 
@@ -504,7 +510,7 @@ final class ClassLoader {
         */
        private function initClassLoader () {
                // Construct the FQFN for the cache
-               if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
+               if (!self::$developerModeEnabled) {
                        // Init cache instances
                        $this->listCacheFile  = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . 'list-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache');
                        $this->classCacheFile = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . 'class-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache');
@@ -518,7 +524,7 @@ final class ClassLoader {
                self::$selfInstance = $this;
 
                // Skip here if no dev-mode
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
+               if (self::$developerModeEnabled) {
                        return;
                }
 
@@ -580,7 +586,7 @@ final class ClassLoader {
                        unset($this->pendingFiles[$fileName]);
 
                        // Developer mode excludes caching (better debugging)
-                       if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
+                       if (!self::$developerModeEnabled) {
                                // Reset cache
                                //* NOISY-DEBUG: */ printf('[%s:%d] classesCached=false' . PHP_EOL, __METHOD__, __LINE__);
                                $this->classesCached = false;
index 80915da609e0e012dfa4bbf2048d2796bbc7159c..804119a5aaba9abcf57885c985194a6fe1273f98 100644 (file)
@@ -33,14 +33,22 @@ use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable {
+       /**
+        * Cached configuration entry 'debug_*_output_timings'
+        */
+       private $debugOutputTimings = 'N';
+
        /**
         * Protected constructor
         *
         * @return      void
         */
        private function __construct () {
-               // Call parent constructor
+               // Call parent constructor first
                parent::__construct(__CLASS__);
+
+               // Cache configuration entry
+               $this->debugOutputTimings = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings');
        }
 
        /**
@@ -71,7 +79,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
                }
 
                // Are debug times enabled?
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
+               if ($this->debugOutputTimings == 'Y') {
                        // Output it first
                        $output = $this->getPrintableExecutionTime() . $output;
                }