]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 23 Feb 2023 05:26:25 +0000 (06:26 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 23 Feb 2023 05:26:25 +0000 (06:26 +0100)
- FrameworkBootstrap::loadInclude() now checks if SplFileInfo is referencing
  to a PHP script
- added some more debug lines

framework/bootstrap/class_FrameworkBootstrap.php
framework/loader/class_ClassLoader.php

index 09895b37bb342865a0eebb51f8615b7a4ad420a8..d3c3c02dc4aaac91d05913318e30f6ef4c85e1fd 100644 (file)
@@ -255,10 +255,16 @@ final class FrameworkBootstrap {
         */
        public static function loadInclude (SplFileInfo $fileInstance) {
                // Should be there ...
-               //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString());
                if (!self::isReadableFile($fileInstance)) {
                        // Abort here
                        throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname()));
+               } elseif (!$fileInstance->isFile()) {
+                       // Not a file
+                       throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a file', $fileInstance->getPathname()));
+               } elseif (substr($fileInstance->__toString(), -4, 4) != '.php') {
+                       // Not PHP script
+                       throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a PHP script', $fileInstance->getPathname()));
                }
 
                // Load it
@@ -337,8 +343,10 @@ final class FrameworkBootstrap {
                 * Now check and load all files, found deprecated files will throw a
                 * warning at the user.
                 */
+               /* NOISY-DEBUG: */ printf('[%s:%d]: self::configAppIncludes()=%d' . PHP_EOL, __METHOD__, __LINE__, count(self::$configAppIncludes));
                foreach (self::$configAppIncludes as $fileName => $status) {
                        // Construct file instance
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status);
                        $fileInstance = new SplFileInfo(sprintf('%s%s.php', self::getDetectedApplicationPath(), $fileName));
 
                        // Determine if this file is wanted/readable/deprecated
@@ -350,6 +358,7 @@ final class FrameworkBootstrap {
                                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
+                               //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status);
                                continue;
                        }
 
@@ -363,6 +372,7 @@ final class FrameworkBootstrap {
                        }
 
                        // Load it
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking self::loadInclude(%s) ...' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString());
                        self::loadInclude($fileInstance);
                }
 
@@ -381,6 +391,7 @@ final class FrameworkBootstrap {
         */
        public static function startApplication () {
                // Is there an application helper instance?
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
                $applicationInstance = call_user_func_array(
                        [
                                'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper', 'getSelfInstance'
@@ -388,6 +399,7 @@ final class FrameworkBootstrap {
                );
 
                // Some sanity checks
+               //* NOISY-DEBUG: */ printf('[%s:%d]: applicationInstance=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationInstance->__toString());
                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.',
@@ -408,11 +420,15 @@ final class FrameworkBootstrap {
                }
 
                // Now call all methods in one go
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Initializing application ...' . PHP_EOL, __METHOD__, __LINE__);
                foreach (['setupApplicationData', 'initApplication', 'launchApplication'] as $methodName) {
                        // Call method
-                       //*NOISY-DEBUG: */ printf('[%s:%d]: Calling methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName);
+                       //*NOISY-DEBUG: */ printf('[%s:%d]: Invoking methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName);
                        call_user_func([$applicationInstance, $methodName]);
                }
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
 
        /**
index 48021b4d6eb1ca94e02426755b53e1b864dd3694..7d29b2aabafee4627530c23f6fa13e9caff51262 100644 (file)
@@ -625,6 +625,8 @@ final class ClassLoader {
                // Skip here if no dev-mode
                //* NOISY-DEBUG: */ printf('[%s:%d]: self::developerModeEnabled=%d' . PHP_EOL, __METHOD__, __LINE__, intval(self::$developerModeEnabled));
                if (self::$developerModeEnabled) {
+                       // Developer mode is enabled
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: Developer mode is enabled - EXIT!' . PHP_EOL, __METHOD__, __LINE__);
                        return;
                }
 
@@ -634,8 +636,10 @@ final class ClassLoader {
                $this->classCacheFile = new SplFileInfo(self::$configInstance->getConfigEntry('local_database_path') . 'class-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache');
 
                // Is the cache there?
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Checking this->listCacheFile=%s ...' . PHP_EOL, __METHOD__, __LINE__, $this->listCacheFile);
                if (FrameworkBootstrap::isReadableFile($this->listCacheFile)) {
                        // Load and convert it
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: Loading %s ...' . PHP_EOL, __METHOD__, __LINE__, $this->listCacheFile);
                        $this->pendingFiles = json_decode(file_get_contents($this->listCacheFile->getPathname()));
 
                        // List has been restored from cache!
@@ -643,8 +647,10 @@ final class ClassLoader {
                }
 
                // Does the class cache exist?
+               //* NOISY-DEBUG: */ printf('[%s:%d]: Checking this->classCacheFile=%s ...' . PHP_EOL, __METHOD__, __LINE__, $this->classCacheFile);
                if (FrameworkBootstrap::isReadableFile($this->classCacheFile)) {
                        // Then include it
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking FrameworkBootstrap::loadInclude(%s) ...' . PHP_EOL, __METHOD__, __LINE__, $this->classCacheFile);
                        FrameworkBootstrap::loadInclude($this->classCacheFile);
 
                        // Mark the class cache as loaded
@@ -666,13 +672,15 @@ final class ClassLoader {
         */
        private function loadClassFile (string $className) {
                // The class name should contain at least 2 back-slashes, so split at them
-               //* NOISY-DEBUG: */ printf('[%s:%d] className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className);
+               //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className);
                $classNameParts = explode("\\", $className);
 
                // Get last element
+               //* NOISY-DEBUG: */ printf('[%s:%d]: classNameParts()=%d' . PHP_EOL, __METHOD__, __LINE__, count($classNameParts));
                $shortClassName = array_pop($classNameParts);
 
                // Create a name with prefix and suffix
+               //* NOISY-DEBUG: */ printf('[%s:%d]: this->prefix=%s,shortClassName=%s,this->suffix=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $this->prefix, $shortClassName, $this->suffix);
                $fileName = sprintf('%s%s%s', $this->prefix, $shortClassName, $this->suffix);
 
                // Now look it up in our index