From: Roland Häder Date: Wed, 2 Dec 2020 10:11:30 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=00571e55f7ea67ec80e36a3a293b0b7162c83572;p=core.git Continued: - rewrote deprecated DEVELOPER constant to developer_mode_enabled configuration entry - added missing "import" line for exception Signed-off-by: Roland Häder --- diff --git a/framework/config-global.php b/framework/config-global.php index 2476e47e..4de24029 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -461,7 +461,7 @@ $cfg->setConfigEntry('extension_uuid_loaded', false); $cfg->setConfigEntry('registry_iterator_class', 'Org\Mxchange\CoreFramework\Iterator\Registry\RegistryIterator'); // CFG: QUIET-DNS-RESOLVER -$cfg->setConfigEntry('quiet_dns_resolver', FALSE); +$cfg->setConfigEntry('quiet_dns_resolver', false); // CFG: THOUSANDS-SEPARATOR $cfg->setConfigEntry('thousands_separator', '.'); @@ -477,3 +477,6 @@ $cfg->setConfigEntry('crypto_openssl_stream_class', 'Org\Mxchange\CoreFramework\ // CFG: CRYPTO-NULL-STREAM-CLASS $cfg->setConfigEntry('crypto_null_stream_class', 'Org\Mxchange\CoreFramework\Stream\Crypto\Null\NullCryptoStream'); + +// CFG: DEVELOPER-MODE-ENABLED +$cfg->setConfigEntry('developer_mode_enabled', true); diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 6e969ccb..0d5560a5 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -4,6 +4,7 @@ namespace Org\Mxchange\CoreFramework\Configuration; // Import framework stuff +use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException; use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; @@ -135,7 +136,7 @@ class FrameworkConfiguration implements Registerable { if (!$this->isConfigurationEntrySet($configKey)) { // Entry was not found! throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND); - } // END - if + } // Return the requested value return self::$config[$configKey]; @@ -218,7 +219,7 @@ class FrameworkConfiguration implements Registerable { if (!$this->isConfigurationEntrySet($configKey)) { // Entry was not found! throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND); - } // END - if + } // Unset it unset(self::$config[$configKey]); diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 194e89f1..72d25add 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -154,9 +154,9 @@ class ClassLoader { */ public function __destruct () { // Skip here if dev-mode - if (defined('DEVELOPER')) { + if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { return; - } // END - if + } // Skip here if already cached if ($this->listCached === false) { @@ -168,7 +168,7 @@ class ClassLoader { // And write whole list $fileObject->fwrite($cacheContent); - } // END - if + } // Skip here if already cached if ($this->classesCached === false) { @@ -181,14 +181,14 @@ class ClassLoader { // Load the file // @TODO Add some uglifying code (compress) here $cacheContent .= $fileObject->fread($fileInstance->getSize()); - } // END - foreach + } // Open file $fileObject = $this->classCacheFile->openFile('w'); // And write it away $fileObject->fwrite($cacheContent); - } // END - if + } } /** @@ -214,10 +214,8 @@ class ClassLoader { * @return void */ public static function scanFrameworkClasses () { - // Trace message - //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); - // Get loader instance + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $loaderInstance = self::getSelfInstance(); // Get config instance @@ -225,10 +223,8 @@ class ClassLoader { // Load all classes foreach (self::$frameworkPaths as $shortPath) { - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); - // Generate full path from it + //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); $realPathName = realpath(sprintf( '%smain%s%s%s', $configInstance->getConfigEntry('framework_base_path'), @@ -237,10 +233,8 @@ class ClassLoader { DIRECTORY_SEPARATOR )); - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: realPathName=%s' . PHP_EOL, __METHOD__, __LINE__, $realPathName); - // Is it not false and accessible? + //* NOISY-DEBUG: */ printf('[%s:%d]: realPathName=%s' . PHP_EOL, __METHOD__, __LINE__, $realPathName); if (is_bool($realPathName)) { // Skip this continue; @@ -251,7 +245,7 @@ class ClassLoader { // Try to load the framework classes $loaderInstance->scanClassPath($realPathName); - } // END - foreach + } // Trace message //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); @@ -263,10 +257,8 @@ class ClassLoader { * @return void */ public static function scanApplicationClasses () { - // Trace message - //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); - // Get loader instance + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $loaderInstance = self::getSelfInstance(); // Get config instance @@ -274,10 +266,8 @@ class ClassLoader { // Load all classes for the application foreach (self::$frameworkPaths as $shortPath) { - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); - // Create path name + //* NOISY-DEBUG: */ printf('[%s:%d]: shortPath=%s' . PHP_EOL, __METHOD__, __LINE__, $shortPath); $pathName = realpath(sprintf( '%s%s%s%s%s', $configInstance->getConfigEntry('application_base_path'), @@ -287,15 +277,13 @@ class ClassLoader { $shortPath )); - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); - // Is the path readable? + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); if (is_dir($pathName)) { // Try to load the application classes $loaderInstance->scanClassPath($pathName); - } // END - if - } // END - foreach + } + } // Trace message //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); @@ -326,21 +314,17 @@ class ClassLoader { $shortPath ); - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s - BEFORE!' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); - // Try to find it + //* NOISY-DEBUG: */ printf('[%s:%d]: pathName[%s]=%s - BEFORE!' . PHP_EOL, __METHOD__, __LINE__, gettype($pathName), $pathName); $realPathName = realpath($pathName); - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: realPathName[%s]=%s - AFTER!' . PHP_EOL, __METHOD__, __LINE__, gettype($realPathName), $realPathName); - // Is the path readable? + //* NOISY-DEBUG: */ printf('[%s:%d]: realPathName[%s]=%s - AFTER!' . PHP_EOL, __METHOD__, __LINE__, gettype($realPathName), $realPathName); if ((is_dir($realPathName)) && (is_readable($realPathName))) { // Try to load the application classes ClassLoader::getSelfInstance()->scanClassPath($realPathName); - } // END - if - } // END - foreach + } + } // Trace message //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); @@ -364,10 +348,8 @@ class ClassLoader { * @return void */ public static function registerTestsPath (string $relativePath) { - // Trace message - //* NOISY-DEBUG: */ printf('[%s:%d]: relativePath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $relativePath); - // "Register" it + //* NOISY-DEBUG: */ printf('[%s:%d]: relativePath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $relativePath); self::$testPaths[$relativePath] = $relativePath; // Trace message @@ -401,7 +383,7 @@ class ClassLoader { if (is_null(self::$selfInstance)) { // Get a new one self::$selfInstance = ClassLoader::createClassLoader(FrameworkBootstrap::getConfigurationInstance()); - } // END - if + } // Return the instance return self::$selfInstance; @@ -419,7 +401,7 @@ class ClassLoader { if ($this->listCached === true) { // Abort here return; - } // END - if + } // Keep it in class for later usage $this->ignoreList = $ignoreList; @@ -466,7 +448,7 @@ class ClassLoader { // Skip non-file entries //* NOISY-DEBUG: */ printf('[%s:%d] SKIP: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); continue; - } // END - if + } // Is this file wanted? //* NOISY-DEBUG: */ printf('[%s:%d] FOUND: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); @@ -482,7 +464,7 @@ class ClassLoader { // Advance to next entry //* NOISY-DEBUG: */ printf('[%s:%d] NEXT: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); $iteratorInstance->next(); - } // END - while + } } /** @@ -504,7 +486,7 @@ class ClassLoader { $includeList = ''; foreach ($this->loadedClasses as $classFile) { $includeList .= basename($classFile) . '
' . PHP_EOL; - } // END - foreach + } // And return it return $includeList; @@ -521,10 +503,11 @@ class ClassLoader { $this->configInstance = $configInstance; // Construct the FQFN for the cache - if (!defined('DEVELOPER')) { + 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'); - } // END - if + } // Set suffix and prefix from configuration $this->suffix = $configInstance->getConfigEntry('class_suffix'); @@ -534,9 +517,9 @@ class ClassLoader { self::$selfInstance = $this; // Skip here if no dev-mode - if (defined('DEVELOPER')) { + if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { return; - } // END - if + } // Is the cache there? if (FrameworkBootstrap::isReadableFile($this->listCacheFile)) { @@ -545,7 +528,7 @@ class ClassLoader { // List has been restored from cache! $this->listCached = true; - } // END - if + } // Does the class cache exist? if (FrameworkBootstrap::isReadableFile($this->classCacheFile)) { @@ -554,7 +537,7 @@ class ClassLoader { // Mark the class cache as loaded $this->classesCached = true; - } // END - if + } } /** @@ -575,7 +558,7 @@ class ClassLoader { if ((self::$strictNamingConvention === true) && (count($classNameParts) < 5)) { // Namespace scheme is: Project\Package[\SubPackage...] throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className)); - } // END - if + } // Get last element $shortClassName = array_pop($classNameParts); @@ -602,11 +585,11 @@ class ClassLoader { unset($this->foundClasses[$fileName]); // Developer mode excludes caching (better debugging) - if (!defined('DEVELOPER')) { + if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { // Reset cache //* NOISY-DEBUG: */ printf('[%s:%d] classesCached=false' . PHP_EOL, __METHOD__, __LINE__); $this->classesCached = false; - } // END - if + } } else { // Not found //* NOISY-DEBUG: */ printf('[%s:%d] 404: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName); diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 274fb7d6..6280c515 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -829,7 +829,7 @@ Loaded includes: if ($this->isFieldSet($fieldName)) { // Get it $fieldValue = $fieldArray[$fieldName2]; - } elseif (defined('DEVELOPER')) { + } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { // Missing field entry, may require debugging self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray
=' . print_r($fieldArray, true) . '
,fieldName=' . $fieldName . ' not found!'); } else { @@ -881,7 +881,7 @@ Loaded includes: */ public function deprecationWarning ($message) { // Is developer mode active? - if (defined('DEVELOPER')) { + if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { // Debug instance is there? if (!is_null($this->getDebugInstance())) { // Output stub message diff --git a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php index d735b561..08737bdf 100644 --- a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php +++ b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php @@ -4,6 +4,7 @@ namespace Org\Mxchange\CoreFramework\Filter\Discovery\Payment; // Import framework stuff use Org\Mxchange\CoreFramework\Action\PerformableAction; +use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Filter\BaseFilter; use Org\Mxchange\CoreFramework\Filter\Chain\FilterChainException; diff --git a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php index b97e0810..2dd3319c 100644 --- a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php +++ b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Helper; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration; +use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; diff --git a/index.php b/index.php index 79e7ce8c..818fb738 100644 --- a/index.php +++ b/index.php @@ -274,9 +274,6 @@ final class ApplicationEntryPoint { } } -// Developer mode active? Comment out if no dev! -define('DEVELOPER', true); - // Log all exceptions (only debug! This option can create large error logs) //define('LOG_EXCEPTIONS', true); diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index d1a5033b..6506e2d6 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Configuration; // Inport framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration; +use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException; use Org\Mxchange\CoreFramework\Loader\ClassLoader; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;