]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 6 Dec 2020 10:22:10 +0000 (11:22 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 6 Dec 2020 10:22:10 +0000 (11:22 +0100)
- configuration keys __detected_* are abusive to the configuration class,
  faster and more confirm is to use static class fields and static getter
  for it.

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/bootstrap/class_FrameworkBootstrap.php
framework/loader/class_ClassLoader.php

index 5d9aa02757ef55375523b11c3d96fae8d16c9ff9..f6fe09405315bbfb7a97361f4f037ffe76508934 100644 (file)
@@ -105,6 +105,16 @@ final class FrameworkBootstrap {
                'starter'                 => 'deprecated',
        ];
 
+       /**
+        * Detected application's name
+        */
+       private static $detectedApplicationName;
+
+       /**
+        * Detected application's full path
+        */
+       private static $detectedApplicationPath;
+
        /**
         * Private constructor, no instance is needed from this class as only
         * static methods exist.
@@ -129,6 +139,24 @@ final class FrameworkBootstrap {
                return self::$configurationInstance;
        }
 
+       /**
+        * Getter for detected application name
+        *
+        * @return      $detectedApplicationName        Detected name of application
+        */
+       public static function getDetectedApplicationName () {
+               return self::$detectedApplicationName;
+       }
+
+       /**
+        * Getter for detected application's full path
+        *
+        * @return      $detectedApplicationPath        Detected full path of application
+        */
+       public static function getDetectedApplicationPath () {
+               return self::$detectedApplicationPath;
+       }
+
        /**
         * "Getter" to get response/request type from analysis of the system.
         *
@@ -270,7 +298,7 @@ final class FrameworkBootstrap {
 
                /*
                 * 2) Determine the request type, console or web and store request and
-                *    response here. This also initializes the request instance will
+                *    response here. This also initializes the request instance with
                 *    all given parameters (see doc-tag for possible sources of
                 *    parameters).
                 */
@@ -292,25 +320,21 @@ final class FrameworkBootstrap {
         * @return      void
         */
        public static function prepareApplication () {
-               // Configuration entry '__detected_app_name' must be set, get it here, including full path
-               $application = self::getConfigurationInstance()->getConfigEntry('__detected_app_name');
-               $fullPath    = self::getConfigurationInstance()->getConfigEntry('__detected_full_app_path');
-
                /*
                 * Now check and load all files, found deprecated files will throw a
                 * warning at the user.
                 */
                foreach (self::$configAppIncludes as $fileName => $status) {
                        // Construct file instance
-                       $fileInstance = new SplFileInfo(sprintf('%s%s.php', $fullPath, $fileName));
+                       $fileInstance = new SplFileInfo(sprintf('%s%s.php', self::getDetectedApplicationPath(), $fileName));
 
                        // Determine if this file is wanted/readable/deprecated
                        if (($status == 'required') && (!self::isReadableFile($fileInstance))) {
                                // Nope, required file cannot be found/read from
-                               ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', $application, $fileInstance->getBasename()));
+                               ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', self::getDetectedApplicationName(), $fileInstance->getBasename()));
                        } elseif (($fileInstance->isFile()) && (!$fileInstance->isReadable())) {
                                // Found, not readable file
-                               ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), $application));
+                               ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), self::getDetectedApplicationName()));
                        } elseif (($status != 'required') && (!self::isReadableFile($fileInstance))) {
                                // Not found but optional/deprecated file, skip it
                                continue;
@@ -319,7 +343,7 @@ final class FrameworkBootstrap {
                        // Is the file deprecated?
                        if ($status == 'deprecated') {
                                // Issue warning
-                               trigger_error(sprintf('Deprecated file "%s.php" found, will not load it to avoid problems. Please remove it from your application "%s" to avoid this warning.', $fileName, $application), E_USER_WARNING);
+                               trigger_error(sprintf('Deprecated file "%s.php" found, will not load it to avoid problems. Please remove it from your application "%s" to avoid this warning.', $fileName, self::getDetectedApplicationName()), E_USER_WARNING);
 
                                // Skip loading deprecated file
                                continue;
@@ -340,9 +364,6 @@ final class FrameworkBootstrap {
         * @return      void
         */
        public static function startApplication () {
-               // Configuration entry '__detected_app_name' must be set, get it here
-               $application = self::getConfigurationInstance()->getConfigEntry('__detected_app_name');
-
                // Is there an application helper instance?
                $applicationInstance = call_user_func_array(
                        array(
@@ -354,19 +375,19 @@ final class FrameworkBootstrap {
                if ((empty($applicationInstance)) || (is_null($applicationInstance))) {
                        // Something went wrong!
                        ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because the helper class <span class="class_name">%s</span> is not loaded.',
-                               $application,
+                               self::getDetectedApplicationName(),
                                'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper'
                        ));
                } elseif (!is_object($applicationInstance)) {
                        // No object!
                        ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because &#39;app&#39; is not an object (%s).',
-                               $application,
+                               self::getDetectedApplicationName(),
                                gettype($applicationInstance)
                        ));
                } elseif (!($applicationInstance instanceof ManageableApplication)) {
                        // Missing interface
                        ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because &#39;app&#39; is lacking required interface ManageableApplication.',
-                               $application
+                               self::getDetectedApplicationName()
                        ));
                }
 
@@ -628,19 +649,19 @@ final class FrameworkBootstrap {
                }
 
                // Get it for local usage
-               $application = self::getRequestInstance()->getRequestElement('app');
+               $applicationName = self::getRequestInstance()->getRequestElement('app');
 
                // Secure it, by keeping out tags
-               $application = htmlentities(strip_tags($application), ENT_QUOTES);
+               $applicationName = htmlentities(strip_tags($applicationName), ENT_QUOTES);
 
                // Secure it a little more with a reg.exp.
-               $application = preg_replace('/([^a-z0-9_-])+/i', '', $application);
+               $applicationName = preg_replace('/([^a-z0-9_-])+/i', '', $applicationName);
 
                // Construct FQPN (Full-Qualified Path Name) for ApplicationHelper class
                $applicationPath = sprintf(
                        '%s%s%s',
                        self::getConfigurationInstance()->getConfigEntry('application_base_path'),
-                       $application,
+                       $applicationName,
                        DIRECTORY_SEPARATOR
                );
 
@@ -648,12 +669,12 @@ final class FrameworkBootstrap {
                // Is the path there? This secures a bit the parameter (from untrusted source).
                if ((!is_dir($applicationPath)) || (!is_readable($applicationPath))) {
                        // Not found or not readable
-                       ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $application));
+                       ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $applicationName));
                }
 
                // Set the detected application's name and full path for later usage
-               self::getConfigurationInstance()->setConfigEntry('__detected_full_app_path', $applicationPath);
-               self::getConfigurationInstance()->setConfigEntry('__detected_app_name'     , $application);
+               self::$detectedApplicationPath = $applicationPath;
+               self::$detectedApplicationName = $applicationName;
        }
 
        /**
index 4c1ce5817fb3c2dcc30e1c588ade86733d89f6a9..b47a2e6fb59bde86c133d824aeea5f5966448825 100644 (file)
@@ -272,7 +272,7 @@ class ClassLoader {
                                '%s%s%s%s%s',
                                $configInstance->getConfigEntry('application_base_path'),
                                DIRECTORY_SEPARATOR,
-                               $configInstance->getConfigEntry('__detected_app_name'),
+                               FrameworkBootstrap::getDetectedApplicationName(),
                                DIRECTORY_SEPARATOR,
                                $shortPath
                        ));
@@ -505,8 +505,8 @@ class ClassLoader {
                // Construct the FQFN for the cache
                if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) {
                        // Init cache instances
-                       $this->listCacheFile  = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('__detected_app_name') . '.cache');
-                       $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('__detected_app_name') . '.cache');
+                       $this->listCacheFile  = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache');
+                       $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache');
                }
 
                // Set suffix and prefix from configuration