From 88202e101f3766fd96b6fc9440e15d20a9ed6a67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Aug 2025 22:49:29 +0200 Subject: [PATCH] Continued: - switched to "new" [] style instead of old-fashioned array() - changed type-hint from DebugMiddleware (class) to Logger (interface) --- .../config/class_FrameworkConfiguration.php | 2 +- .../classes/class_BaseFrameworkSystem.php | 63 ++++--------------- .../utils/strings/class_StringUtils.php | 23 +++++++ .../interfaces/class_FrameworkInterface.php | 10 +-- .../main/interfaces/lists/class_Listable.php | 8 --- 5 files changed, 40 insertions(+), 66 deletions(-) diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 257eede2..1a6a26a4 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -210,7 +210,7 @@ class FrameworkConfiguration implements Registerable { //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s - AFTER!' . PHP_EOL, __METHOD__, __LINE__, $configKey); if (!$this->isConfigurationEntrySet($configKey)) { // Entry was not found! - throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND); + throw new NoConfigEntryException([__CLASS__, $configKey], self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND); } // Unset it diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 1d1ee397..81a03b29 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Loader\ClassLoader; +use Org\Mxchange\CoreFramework\Logging\Logger; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware; use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry; @@ -393,10 +394,10 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac /** * Setter for debug instance * - * @param $debugInstance The instance for debug output class + * @param $debugInstance An instance of a Logger class * @return void */ - public final function setDebugInstance (DebugMiddleware $debugInstance): void { + public final function setDebugInstance (Logger $debugInstance): void { self::$debugInstance = $debugInstance; } @@ -405,7 +406,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac * * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput */ - public final function getDebugInstance (): DebugMiddleware { + public final function getDebugInstance (): Logger { return self::$debugInstance; } @@ -599,7 +600,7 @@ Loaded includes: * @throws InvalidArgumentException If a parameter has an invalid value * @deprecated Not fully, as the new Logger facilities are not finished yet. */ - public final static function createDebugInstance (string $className, int $lineNumber = 0): DebugMiddleware { + public final static function createDebugInstance (string $className, int $lineNumber = 0): Logger { // Validate parameter //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s,lineNumber[%s]=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className, gettype($lineNumber), $lineNumber); if (empty($className)) { @@ -629,25 +630,6 @@ Loaded includes: return self::$debugInstance; } - /** - * Simple output of a message with line-break - * - * @param $message Message to output - * @return void - * @throws InvalidArgumentException If a paramter has an invalid value - */ - public function outputLine (string $message): void { - // Check parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: message=%s - CALLED!', $message)); - if (empty($message)) { - // Throw IAE - throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); - } - - // Simply output it - print($message . PHP_EOL); - } - /** * Marks up the code by adding e.g. line numbers * @@ -699,12 +681,12 @@ Loaded includes: * @return $entry An array with database entries * @throws NullPointerException If the database result is not found * @throws InvalidDatabaseResultException If the database result is invalid - * @deprecated Monolithic method, should be moved to proper classes + * @deprecated Monolithic method, should be avoided by using DatabaseResult classes instead */ protected final function getDatabaseEntry (): array { // This method is deprecated /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: CALLED!'); - $this->deprecationWarning('Monolithic method, should be moved to proper classes'); + $this->deprecationWarning('Monolithic method, should be avoided by using DatabaseResult classes instead'); // Is there an instance? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance[]=%s', gettype($this->getResultInstance()))); @@ -743,7 +725,7 @@ Loaded includes: * @return $fieldValue Field value from the user * @throws NullPointerException If the result instance is null * @throws InvalidArgumentException If a parameter is not valid - * @deprecated Monolithic method, should be moved to proper classes + * @deprecated Monolithic method, should be avoided by using DatabaseResult classes instead */ public final function getField (string $fieldName): mixed { // Check parameter @@ -754,7 +736,7 @@ Loaded includes: } // This method is deprecated - $this->deprecationWarning('Monolithic method, should be moved to proper classes'); + $this->deprecationWarning('Monolithic method, should be avoided by using DatabaseResult classes instead'); // Default field value $fieldValue = NULL; @@ -801,7 +783,7 @@ Loaded includes: * @return $isSet Whether the given field name is set * @throws NullPointerException If the result instance is null * @throws InvalidArgumentException If a parameter is not valid - * @deprecated Monolithic method, should be moved to proper classes + * @deprecated Monolithic method, should be avoided by using DatabaseResult classes instead */ public function isFieldSet (string $fieldName): bool { // Check parameter @@ -812,7 +794,7 @@ Loaded includes: } // This method is deprecated - $this->deprecationWarning('Monolithic method, should be moved to proper classes'); + $this->deprecationWarning('Monolithic method, should be avoided by using DatabaseResult classes instead'); // Get result instance $resultInstance = $this->getResultInstance(); @@ -952,29 +934,6 @@ Loaded includes: return $hasSlept; } - /** - * Checks whether the given encoded data was encoded with Base64 - * - * @param $encodedData Encoded data we shall check - * @return $isBase64 Whether the encoded data is Base64 - * @throws InvalidArgumentException If a parameter is not valid - */ - protected function isBase64Encoded (string $encodedData): bool { - // Check parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: encodedData=%s - CALLED!', $encodedData)); - if (empty($encodedData)) { - // Throw IAE - throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); - } - - // Determine it - $isBase64 = (@base64_decode($encodedData, true) !== false); - - // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isBase64=%d - EXIT!', intval($isBase64))); - return $isBase64; - } - /** * Getter for startup time in miliseconds * diff --git a/framework/main/classes/utils/strings/class_StringUtils.php b/framework/main/classes/utils/strings/class_StringUtils.php index a5ad4710..0bce293f 100644 --- a/framework/main/classes/utils/strings/class_StringUtils.php +++ b/framework/main/classes/utils/strings/class_StringUtils.php @@ -532,4 +532,27 @@ final class StringUtils extends BaseFrameworkSystem { return $ret; } + /** + * Checks whether the given encoded data was encoded with Base64 + * + * @param $encodedData Encoded data we shall check + * @return $isBase64 Whether the encoded data is Base64 + * @throws InvalidArgumentException If a parameter is not valid + */ + public static function isBase64Encoded (string $encodedData): bool { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: encodedData=%s - CALLED!', $encodedData)); + if (empty($encodedData)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + + // Determine it + $isBase64 = (@base64_decode($encodedData, true) !== false); + + // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isBase64=%d - EXIT!', intval($isBase64))); + return $isBase64; + } + } diff --git a/framework/main/interfaces/class_FrameworkInterface.php b/framework/main/interfaces/class_FrameworkInterface.php index 8c1003d5..792ef7c4 100644 --- a/framework/main/interfaces/class_FrameworkInterface.php +++ b/framework/main/interfaces/class_FrameworkInterface.php @@ -44,7 +44,7 @@ interface FrameworkInterface { * @return $fieldValue Field value from the user * @throws NullPointerException If the result instance is null */ - function getField (string $fieldName); + function getField (string $fieldName): mixed; /** * Checks if given field is set @@ -53,7 +53,7 @@ interface FrameworkInterface { * @return $isSet Whether the given field name is set * @throws NullPointerException If the result instance is null */ - function isFieldSet (string $fieldName); + function isFieldSet (string $fieldName): bool; /** * Setter for call-back instance @@ -61,7 +61,7 @@ interface FrameworkInterface { * @param $callbackInstance An instance of a FrameworkInterface class * @return void */ - function setCallbackInstance (FrameworkInterface $callbackInstance); + function setCallbackInstance (FrameworkInterface $callbackInstance): void; /** * Checks whether an object equals this object. You should overwrite this @@ -70,13 +70,13 @@ interface FrameworkInterface { * @param $objectInstance An instance of a FrameworkInterface object * @return $equals Whether both objects equals */ - function equals (FrameworkInterface $objectInstance); + function equals (FrameworkInterface $objectInstance): bool; /** * Generates a code for hashes from this class * * @return $hashCode The hash code respresenting this class */ - function hashCode (); + function hashCode (): int; } diff --git a/framework/main/interfaces/lists/class_Listable.php b/framework/main/interfaces/lists/class_Listable.php index fc514b72..ba296116 100644 --- a/framework/main/interfaces/lists/class_Listable.php +++ b/framework/main/interfaces/lists/class_Listable.php @@ -95,12 +95,4 @@ interface Listable extends FrameworkInterface, IteratorAggregate { */ function clearList (): void; - /** - * Setter for call-back instance - * - * @param $callbackInstance An instance of a FrameworkInterface class - * @return void - */ - function setCallbackInstance (FrameworkInterface $callbackInstance): void; - } -- 2.39.5