From a1ed2619f78b78e0f7f820ee75c0900ce5f8b553 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Feb 2023 06:26:25 +0100 Subject: [PATCH] Continued: - FrameworkBootstrap::loadInclude() now checks if SplFileInfo is referencing to a PHP script - added some more debug lines --- .../bootstrap/class_FrameworkBootstrap.php | 20 +++++++++++++++++-- framework/loader/class_ClassLoader.php | 10 +++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index 09895b37..d3c3c02d 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -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 %s could not be launched because the helper class %s 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__); } /** diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 48021b4d..7d29b2aa 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -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 -- 2.39.5