From b9efd06b24231e8edefcb83c3e6dca340647068b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 12 Dec 2021 00:13:14 +0100 Subject: [PATCH 1/1] Continued: - moved getCacheKeyByCriteria() to BaseDatabaseFrontend class, maybe not the final resting place, but better than in the generic, bloated BaseFrameworkSystem class - Introduced BaseXmlTemplateEngine->$initMethodName to avoid an additional invocation of StringUtils::convertToClassName() on each invocation of startElement() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../config/class_FrameworkConfiguration.php | 8 +++---- .../classes/class_BaseFrameworkSystem.php | 21 ------------------- .../frontend/class_BaseDatabaseFrontend.php | 20 ++++++++++++++++++ .../classes/factories/class_BaseFactory.php | 20 +++++++++++++++++- .../xml/class_BaseXmlTemplateEngine.php | 8 ++++++- .../utils/strings/class_StringUtils.php | 8 +++++++ .../debug/class_DebugMiddleware.php | 8 +------ 7 files changed, 59 insertions(+), 34 deletions(-) diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index ee54fa0d..9f1ad0df 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -88,7 +88,7 @@ class FrameworkConfiguration implements Registerable { // Is it null? if (empty($configKey)) { // Entry is empty - throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + throw new InvalidArgumentException('Parameter "configKey" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } // Is it set? @@ -111,7 +111,7 @@ class FrameworkConfiguration implements Registerable { //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $configKey); if (empty($configKey)) { // Entry is empty - throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + throw new InvalidArgumentException('Parameter "configKey" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } // Convert dashes to underscore @@ -143,7 +143,7 @@ class FrameworkConfiguration implements Registerable { //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s,configValue[]=%s' . PHP_EOL, __METHOD__, __LINE__, $configKey, gettype($configValue)); if (empty($configKey)) { // Entry is empty - throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + throw new InvalidArgumentException('Parameter "configKey" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } elseif ((is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) { // These cannot be set as this is not intended for configuration values, please use FrameworkArrayObject instead. throw new InvalidArgumentException(sprintf('configValue[]=%s for configKey=%s is not supported.', gettype($configValue), $configKey), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED); @@ -198,7 +198,7 @@ class FrameworkConfiguration implements Registerable { //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $configKey); if (empty($configKey)) { // Entry is empty - throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + throw new InvalidArgumentException('Parameter "configKey" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); } // Convert dashes to underscore diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 77cc954d..38a45f3d 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -4,7 +4,6 @@ namespace Org\Mxchange\CoreFramework\Object; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; -use Org\Mxchange\CoreFramework\Criteria\Criteria; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException; @@ -966,26 +965,6 @@ Loaded includes: return $isBase64; } - /** - * Gets a cache key from Criteria instance - * - * @param $criteriaInstance An instance of a Criteria class - * @param $onlyKeys Only use these keys for a cache key - * @return $cacheKey A cache key suitable for lookup/storage purposes - */ - protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) { - // Generate it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!'); - $cacheKey = sprintf('%s@%s', - $this->__toString(), - $criteriaInstance->getCacheKey($onlyKeys) - ); - - // And return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!'); - return $cacheKey; - } - /** * Getter for startup time in miliseconds * diff --git a/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php b/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php index b1e49663..f85f4bad 100644 --- a/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php +++ b/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php @@ -89,6 +89,26 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem { return $this->tableName; } + /** + * Gets a cache key from Criteria instance + * + * @param $criteriaInstance An instance of a Criteria class + * @param $onlyKeys Only use these keys for a cache key + * @return $cacheKey A cache key suitable for lookup/storage purposes + */ + protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) { + // Generate it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: criteriaInstance=' . $criteriaInstance->__toString() . ',onlyKeys()=' . count($onlyKeys) . ' - CALLED!'); + $cacheKey = sprintf('%s@%s', + $this->__toString(), + $criteriaInstance->getCacheKey($onlyKeys) + ); + + // And return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!'); + return $cacheKey; + } + /** * 'Inserts' a data set instance into a local file database folder * diff --git a/framework/main/classes/factories/class_BaseFactory.php b/framework/main/classes/factories/class_BaseFactory.php index 0cbd4812..ff082062 100644 --- a/framework/main/classes/factories/class_BaseFactory.php +++ b/framework/main/classes/factories/class_BaseFactory.php @@ -5,6 +5,9 @@ namespace Org\Mxchange\CoreFramework\Factory; // Import framework stuff use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; +// Import SPL stuff +use \InvalidArgumentException; + /** * A general (base) factory * @@ -53,8 +56,16 @@ abstract class BaseFactory extends BaseFrameworkSystem { * Count given object * * @param $fullClassName Name of the class we shall count + * @return void + * @throws InvalidArgumentException If a parameter is not valid */ protected static final function countObject (string $fullClassName) { + // Is the parameter valid? + if (empty($fullClassName)) { + // No empty class name + throw new InvalidArgumentException('fullClassName is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } + // Count it up in total sum self::$total++; @@ -92,8 +103,15 @@ abstract class BaseFactory extends BaseFrameworkSystem { * * @param $fullClassName Full name of class * @return $isCounted Whether given class name is counted + * @throws InvalidArgumentException If a parameter is not valid */ - protected static final function isClassCounted (string $fullClassName) { + public static final function isClassCounted (string $fullClassName) { + // Is the parameter valid? + if (empty($fullClassName)) { + // No empty class name + throw new InvalidArgumentException('fullClassName is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } + // Return isset() result return isset(self::$objectCounters[$fullClassName]); } diff --git a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php index fdff28d1..7ae3382a 100644 --- a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php +++ b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php @@ -86,6 +86,11 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi */ private $xmlCompacting = false; + /** + * Method name for XML template type + */ + private $initMethodName = 'invalid'; + /** * Protected constructor * @@ -114,6 +119,7 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi // Set XML template type and prefix $this->xmlTemplateType = $xmlTemplateType; $this->typePrefix = $typePrefix; + $this->initMethodName = sprintf('init%s', StringUtils::convertToClassName($this->xmlTemplateType)); // Get template instance $applicationInstance = ApplicationHelper::getSelfInstance(); @@ -304,7 +310,7 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi */ public final function startElement ($resource, string $element, array $attributes) { // Initial method name which will never be called... - $methodName = 'init' . StringUtils::convertToClassName($this->xmlTemplateType); + $methodName = $this->initMethodName; // Make the element name lower-case $element = strtolower($element); diff --git a/framework/main/classes/utils/strings/class_StringUtils.php b/framework/main/classes/utils/strings/class_StringUtils.php index 8ca43ddf..947a657a 100644 --- a/framework/main/classes/utils/strings/class_StringUtils.php +++ b/framework/main/classes/utils/strings/class_StringUtils.php @@ -192,6 +192,13 @@ final class StringUtils extends BaseFrameworkSystem { * @return $className Generated class name */ public static final function convertToClassName (string $str) { + // Is the parameter valid? + /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: str=%s - CALLED!', $str)); + if (empty($str)) { + // No empty strings, please + throw new InvalidArgumentException('Parameter "str" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } + // Init class name $className = ''; @@ -205,6 +212,7 @@ final class StringUtils extends BaseFrameworkSystem { } // Return class name + /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STRING-UTILS: className=%s - EXIT!', $className)); return $className; } diff --git a/framework/main/middleware/debug/class_DebugMiddleware.php b/framework/main/middleware/debug/class_DebugMiddleware.php index e6683f9b..3a7913b3 100644 --- a/framework/main/middleware/debug/class_DebugMiddleware.php +++ b/framework/main/middleware/debug/class_DebugMiddleware.php @@ -74,13 +74,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { $isInitialized = false; // Is there a valid output instance provided? - if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) { - // Use the given output instance - $debugInstance->setOutputInstance($outputClass); - - // All fine - $isInitialized = true; - } elseif (class_exists($outputClass)) { + if (class_exists($outputClass)) { // A name for a debug output class has been provided so we try to get it $outputInstance = ObjectFactory::createObjectByName($outputClass); -- 2.39.2