From: Roland Häder Date: Fri, 22 Aug 2025 21:17:35 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8b6198503d4d1ad82aaf6bbaa2fe8c6dfcf009a9;p=core.git Continued: - setRealClass() shouldn't be public (very bad idea) - added more type-hints --- diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 81a03b29..f14443e6 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -386,7 +386,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac * @param $realClass Class name (string) * @return void */ - public final function setRealClass (string $realClass): void { + private function setRealClass (string $realClass): void { // Set real class $this->realClass = $realClass; } diff --git a/framework/main/classes/crypto/class_CryptoHelper.php b/framework/main/classes/crypto/class_CryptoHelper.php index f340b540..8d5b4a00 100644 --- a/framework/main/classes/crypto/class_CryptoHelper.php +++ b/framework/main/classes/crypto/class_CryptoHelper.php @@ -230,7 +230,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { * @param $key Optional key, if none provided, a random key will be generated * @return $encrypted Encrypted string */ - public function encryptString (string $str, string $key = NULL) { + public function encryptString (string $str, string $key = NULL): string { // Encrypt the string through the stream $encrypted = $this->cryptoStreamInstance->encryptStream($str, $key); @@ -244,7 +244,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { * @param $encrypted Encrypted string * @return $str The unencrypted string */ - public function decryptString (string $encrypted) { + public function decryptString (string $encrypted): string { // Encrypt the string through the stream $str = $this->cryptoStreamInstance->decryptStream($encrypted); diff --git a/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php b/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php index 39ac1f27..4b76c43a 100644 --- a/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php +++ b/framework/main/classes/database/frontend/class_BaseDatabaseFrontend.php @@ -126,7 +126,7 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem { ); // And return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FRAMEWORK-SYSTEM: cacheKey=' . $cacheKey . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-DATABASE-FRONTEND: cacheKey=' . $cacheKey . ' - EXIT!'); return $cacheKey; } diff --git a/framework/main/classes/response/class_BaseResponse.php b/framework/main/classes/response/class_BaseResponse.php index 33f6efec..f7717858 100644 --- a/framework/main/classes/response/class_BaseResponse.php +++ b/framework/main/classes/response/class_BaseResponse.php @@ -75,7 +75,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $status New response status * @return void */ - public final function setResponseStatus (string $status) { + public final function setResponseStatus (string $status): void { $this->responseStatus = $status; } @@ -86,7 +86,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $value Value of header element * @return void */ - public final function addHeader (string $name, $value) { + public final function addHeader (string $name, string $value): void { $this->responseHeaders[$name] = $value; } @@ -95,7 +95,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * * @return void */ - public final function resetResponseHeaders () { + public final function resetResponseHeaders (): void { $this->responseHeaders = []; } @@ -105,7 +105,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $output Output we shall sent in the HTTP response * @return void */ - public final function writeToBody (string $output) { + public final function writeToBody (string $output): void { $this->responseBody .= $output; } @@ -115,7 +115,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $output Output we shall sent in the HTTP response * @return void */ - public final function setResponseBody ($output) { + public final function setResponseBody (string $output): void { $this->responseBody = $output; } @@ -125,7 +125,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $responseType Response type * @return void */ - protected final function setResponseType (string $responseType) { + protected final function setResponseType (string $responseType): void { $this->responseType = $responseType; } @@ -135,7 +135,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $responseType Response type * @return void */ - public final function getResponseType () { + public final function getResponseType (): string { return $this->responseType; } @@ -146,7 +146,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $messageId The message id we shall add * @return void */ - public final function addFatalMessage (string $messageId) { + public final function addFatalMessage (string $messageId): void { // Adds the resolved message id to the fatal message list $this->addFatalMessagePlain(FrameworkBootstrap::getLanguageInstance()->getMessage($messageId)); } @@ -157,7 +157,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @param $message The plain message we shall add * @return void */ - public final function addFatalMessagePlain (string $message) { + public final function addFatalMessagePlain (string $message): void { // Adds the resolved message id to the fatal message list $this->pushValueToGenericArrayKey('fatal_messages', 'generic', 'message', $message); } @@ -171,15 +171,15 @@ abstract class BaseResponse extends BaseFrameworkSystem { * @throws ResponseHeadersAlreadySentException Thrown if headers are * already sent */ - public function flushBuffer (bool $force = false) { + public function flushBuffer (bool $force = false): void { // Get application instance $applicationInstance = ApplicationHelper::getSelfInstance(); // Headers already sent? - if ((headers_sent()) && ($force === false)) { + if (!$force && headers_sent()) { // Headers are already sent! throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } elseif (!headers_sent()) { + } elseif ($force || !headers_sent()) { // Send headers out header('HTTP/1.1 ' . $this->responseStatus); @@ -234,7 +234,7 @@ abstract class BaseResponse extends BaseFrameworkSystem { * * @return $defaultCommand Default command for this response */ - public function determineDefaultCommand () { + public function determineDefaultCommand (): string { // Get application instance $applicationInstance = ApplicationHelper::getSelfInstance(); diff --git a/framework/main/classes/response/console/class_ConsoleResponse.php b/framework/main/classes/response/console/class_ConsoleResponse.php index 4cb10564..3243bfa7 100644 --- a/framework/main/classes/response/console/class_ConsoleResponse.php +++ b/framework/main/classes/response/console/class_ConsoleResponse.php @@ -51,7 +51,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * * @return $responseInstance A prepared instance of this class */ - public static final function createConsoleResponse () { + public static final function createConsoleResponse (): Responseable { // Get a new instance $responseInstance = new ConsoleResponse(); @@ -69,7 +69,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { + public function addCookie (string $cookieName, string $cookieValue, bool $encrypted = FALSE, int $expires = NULL): void { //* DEBUG: */ echo $cookieName.'='.$cookieValue."
\n"; DebugMiddleware::getSelfInstance()->partialStub('Naturally unimplemented in console response.'); } @@ -82,7 +82,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function redirectToConfiguredUrl ($configEntry) { + public function redirectToConfiguredUrl (string $configEntry): void { DebugMiddleware::getSelfInstance()->partialStub('Naturally unimplemented in console response.'); } @@ -92,7 +92,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to expire * @return void */ - public function expireCookie ($cookieName) { + public function expireCookie (string $cookieName): void { DebugMiddleware::getSelfInstance()->partialStub('Naturally unimplemented in console response.'); } @@ -102,7 +102,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to refresh * @return void */ - public function refreshCookie ($cookieName) { + public function refreshCookie (string $cookieName): void { DebugMiddleware::getSelfInstance()->partialStub('Naturally unimplemented in console response.'); } @@ -114,7 +114,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException Thrown if headers are already sent */ - public function flushBuffer ($force = false) { + public function flushBuffer (bool $force = false): void { DebugMiddleware::getSelfInstance()->partialStub('Please implement this class.'); } diff --git a/framework/main/classes/response/html/class_HtmlResponse.php b/framework/main/classes/response/html/class_HtmlResponse.php index 5c5beed7..f5f08efb 100644 --- a/framework/main/classes/response/html/class_HtmlResponse.php +++ b/framework/main/classes/response/html/class_HtmlResponse.php @@ -53,7 +53,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * * @return $responseInstance A prepared instance of this class */ - public static final function createHtmlResponse () { + public static final function createHtmlResponse (): Responseable { // Get a new instance $responseInstance = new HtmlResponse(); @@ -74,7 +74,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * @todo If the return statement is removed and setcookie() commented out, * @todo this will send only one cookie out, the first one. */ - public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { + public function addCookie (string $cookieName, string $cookieValue, bool $encrypted = FALSE, int $expires = NULL): void { //* DEBUG: */ echo $cookieName.'='.$cookieValue."
\n"; // Are headers already sent? if (headers_sent()) { @@ -121,7 +121,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function redirectToConfiguredUrl ($configEntry) { + public function redirectToConfiguredUrl (string $configEntry): void { // Get application instance $applicationInstance = ApplicationHelper::getSelfInstance(); @@ -173,7 +173,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to expire * @return void */ - public function expireCookie (string $cookieName) { + public function expireCookie (string $cookieName): void { // Is the cookie there? if (isset($_COOKIE[$cookieName])) { // Then expire it with 20 minutes past @@ -190,7 +190,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to refresh * @return void */ - public function refreshCookie (string $cookieName) { + public function refreshCookie (string $cookieName): void { // Only update existing cookies if (isset($_COOKIE[$cookieName])) { // Update the cookie diff --git a/framework/main/classes/response/image/class_ImageResponse.php b/framework/main/classes/response/image/class_ImageResponse.php index 783c8489..af98531e 100644 --- a/framework/main/classes/response/image/class_ImageResponse.php +++ b/framework/main/classes/response/image/class_ImageResponse.php @@ -59,7 +59,7 @@ class ImageResponse extends BaseResponse implements Responseable { * * @return $responseInstance A prepared instance of this class */ - public static final function createImageResponse () { + public static final function createImageResponse (): Responseable { // Get a new instance $responseInstance = new ImageResponse(); @@ -73,7 +73,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @param $imageInstance An instance of an image * @return void */ - public final function setImageInstance (BaseImage $imageInstance) { + public final function setImageInstance (BaseImage $imageInstance): void { $this->imageInstance = $imageInstance; } @@ -82,7 +82,7 @@ class ImageResponse extends BaseResponse implements Responseable { * * @return $imageInstance An instance of an image */ - public final function getImageInstance () { + public final function getImageInstance (): BaseImage { return $this->imageInstance; } @@ -99,7 +99,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @todo If the return statement is removed and setcookie() commented out, * @todo this will send only one cookie out, the first one. */ - public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { + public function addCookie (string $cookieName, string $cookieValue, bool $encrypted = FALSE, int $expires = NULL): void { // Are headers already sent? if (headers_sent()) { // Throw an exception here @@ -144,7 +144,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function redirectToConfiguredUrl (string $configEntry) { + public function redirectToConfiguredUrl (string $configEntry): void { // Get application instance $applicationInstance = ApplicationHelper::getSelfInstance(); @@ -195,7 +195,7 @@ class ImageResponse extends BaseResponse implements Responseable { * already sent with an exception * @return void */ - public function flushBuffer (bool $force = false) { + public function flushBuffer (bool $force = false): void { // Finish the image $this->getImageInstance()->finishImage(); @@ -218,7 +218,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to expire * @return void */ - public function expireCookie (string $cookieName) { + public function expireCookie (string $cookieName): void { // Is the cookie there? if (isset($_COOKIE[$cookieName])) { // Then expire it with 20 minutes past @@ -235,7 +235,7 @@ class ImageResponse extends BaseResponse implements Responseable { * @param $cookieName Cookie to refresh * @return void */ - public function refreshCookie (string $cookieName) { + public function refreshCookie (string $cookieName): void { // Only update existing cookies if (isset($_COOKIE[$cookieName])) { // Update the cookie diff --git a/framework/main/classes/utils/strings/class_StringUtils.php b/framework/main/classes/utils/strings/class_StringUtils.php index 0bce293f..a73fafbd 100644 --- a/framework/main/classes/utils/strings/class_StringUtils.php +++ b/framework/main/classes/utils/strings/class_StringUtils.php @@ -541,7 +541,7 @@ final class StringUtils extends BaseFrameworkSystem { */ public static function isBase64Encoded (string $encodedData): bool { // Check parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: encodedData=%s - CALLED!', $encodedData)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STRING-UTILS: encodedData=%s - CALLED!', $encodedData)); if (empty($encodedData)) { // Throw IAE throw new InvalidArgumentException('Parameter "encodedData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -551,7 +551,7 @@ final class StringUtils extends BaseFrameworkSystem { $isBase64 = (@base64_decode($encodedData, true) !== false); // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FRAMEWORK-SYSTEM: isBase64=%d - EXIT!', intval($isBase64))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STRING-UTILS: isBase64=%d - EXIT!', intval($isBase64))); return $isBase64; } diff --git a/framework/main/interfaces/crypto/class_Cryptable.php b/framework/main/interfaces/crypto/class_Cryptable.php index d0cbc2b5..39558320 100644 --- a/framework/main/interfaces/crypto/class_Cryptable.php +++ b/framework/main/interfaces/crypto/class_Cryptable.php @@ -39,7 +39,7 @@ interface Cryptable extends FrameworkInterface { * @param $withFixed Whether to include a fixed salt (not recommended in p2p applications) * @return $hashed The hashed and salted string */ - function hashString (string $str, string $oldHash = '', bool $withFixed = true); + function hashString (string $str, string $oldHash = '', bool $withFixed = true): string; /** * Encrypt the string with fixed salt @@ -48,7 +48,7 @@ interface Cryptable extends FrameworkInterface { * @param $key Optional key, if none provided, a random key will be generated * @return $encrypted Encrypted string */ - function encryptString (string $str, string $key = NULL); + function encryptString (string $str, string $key = NULL): string; /** * Decrypt the string with fixed salt @@ -56,6 +56,6 @@ interface Cryptable extends FrameworkInterface { * @param $encrypted Encrypted string * @return $str The unencrypted string */ - function decryptString (string $encrypted); + function decryptString (string $encrypted): string; } diff --git a/framework/main/interfaces/response/class_Responseable.php b/framework/main/interfaces/response/class_Responseable.php index 6c0290b7..7d15b3b0 100644 --- a/framework/main/interfaces/response/class_Responseable.php +++ b/framework/main/interfaces/response/class_Responseable.php @@ -34,7 +34,7 @@ interface Responseable extends FrameworkInterface { * @param $status New response status * @return void */ - function setResponseStatus (string $status); + function setResponseStatus (string $status): void; /** * Adds a header to the response. This method "wraps" the direct header() @@ -47,7 +47,7 @@ interface Responseable extends FrameworkInterface { * @param $value Value of header element * @return void */ - function addHeader (string $name, $value); + function addHeader (string $name, string $value): void; /** * "Writes" data to the response body @@ -55,7 +55,7 @@ interface Responseable extends FrameworkInterface { * @param $output Output we shall sent in the HTTP response * @return void */ - function writeToBody (string $output); + function writeToBody (string $output): void; /** * Flushs the cached HTTP response to the outer world @@ -66,7 +66,7 @@ interface Responseable extends FrameworkInterface { * @throws ResponseHeadersAlreadySentException Thrown if headers are * already sent */ - function flushBuffer (bool $force = false); + function flushBuffer (bool $force = false): void; /** * Adds a fatal message id to the response. The added messages can then be @@ -75,7 +75,7 @@ interface Responseable extends FrameworkInterface { * @param $messageId The message id we shall add * @return void */ - function addFatalMessage (string $messageId); + function addFatalMessage (string $messageId): void; /** * Adds a cookie to the response @@ -87,7 +87,7 @@ interface Responseable extends FrameworkInterface { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL); + function addCookie (string $cookieName, string $cookieValue, bool $encrypted = FALSE, int $expires = NULL): void; /** * Redirect to a configured URL. The URL can be absolute or relative. In @@ -98,7 +98,7 @@ interface Responseable extends FrameworkInterface { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - function redirectToConfiguredUrl (string $configEntry); + function redirectToConfiguredUrl (string $configEntry): void; /** * Expires the given cookie if it is set @@ -106,7 +106,7 @@ interface Responseable extends FrameworkInterface { * @param $cookieName Cookie to expire * @return void */ - function expireCookie (string $cookieName); + function expireCookie (string $cookieName): void; /** * Refreshs a given cookie. This will make the cookie live longer @@ -114,6 +114,6 @@ interface Responseable extends FrameworkInterface { * @param $cookieName Cookie to refresh * @return void */ - function refreshCookie (string $cookieName); + function refreshCookie (string $cookieName): void; }