From 6d28fb6591fef9a9e9cd8133dd8baf3c4b484bbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Aug 2025 23:37:14 +0200 Subject: [PATCH] Continued: - more type-hints added - sometimes set $this as an extra (RNG initializer) instance --- .../commands/html/class_HtmlResendLinkCommand.php | 4 ++-- framework/main/classes/crypto/class_CryptoHelper.php | 2 +- .../classes/helper/captcha/class_BaseCaptcha.php | 2 +- .../main/classes/rng/class_RandomNumberGenerator.php | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php b/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php index 4cf80330..2e75786a 100644 --- a/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php +++ b/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php @@ -81,7 +81,7 @@ class HtmlResendLinkCommand extends BaseCommand implements Commandable { $applicationInstance = ApplicationHelper::getSelfInstance(); // Get a RNG instance (Random Number Generator) - $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); + $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class', [$this]); // Generate a pseudo-random string $randomString = $rngInstance->randomString(255); @@ -102,7 +102,7 @@ class HtmlResendLinkCommand extends BaseCommand implements Commandable { $this->getTemplateInstance()->assignApplicationData(); // Get a mailer class - $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($this->getTemplateInstance(), 'resend_link')); + $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', [$this->getTemplateInstance(), 'resend_link']); // Set this mailer in our template engine $this->getTemplateInstance()->setMailerInstance($mailerInstance); diff --git a/framework/main/classes/crypto/class_CryptoHelper.php b/framework/main/classes/crypto/class_CryptoHelper.php index 8d5b4a00..2f6f437f 100644 --- a/framework/main/classes/crypto/class_CryptoHelper.php +++ b/framework/main/classes/crypto/class_CryptoHelper.php @@ -136,7 +136,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ protected function initHasher (): void { // Initialize the random number generator which is required by some crypto methods - $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class')); + $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', [$this])); // Generate a salt for the hasher $this->generateSalt(); diff --git a/framework/main/classes/helper/captcha/class_BaseCaptcha.php b/framework/main/classes/helper/captcha/class_BaseCaptcha.php index 8fc62058..6cac40b4 100644 --- a/framework/main/classes/helper/captcha/class_BaseCaptcha.php +++ b/framework/main/classes/helper/captcha/class_BaseCaptcha.php @@ -57,7 +57,7 @@ abstract class BaseCaptcha extends BaseHelper implements Helper { */ protected final function initializeRandomNumberGenerator (FrameworkInterface $extraInstance = NULL): void { // Get an RNG from factory - $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance))); + $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', [$extraInstance])); } } diff --git a/framework/main/classes/rng/class_RandomNumberGenerator.php b/framework/main/classes/rng/class_RandomNumberGenerator.php index 5031f705..f95c9abd 100644 --- a/framework/main/classes/rng/class_RandomNumberGenerator.php +++ b/framework/main/classes/rng/class_RandomNumberGenerator.php @@ -104,7 +104,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * @return void * @todo Add site key for stronger salt! */ - protected function initRng ($extraInstance) { + protected function initRng (FrameworkInterface $extraInstance = NULL): void { // Get the prime number from config $this->prime = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('math_prime'); @@ -155,7 +155,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * @param $length Length of the string, default: 128 * @return $randomString The pseudo-random string */ - public function randomString ($length = -1) { + public function randomString (int $length = 0): string { // Is the number <1, then fix it to default length if ($length < 1) { $length = $this->rndStrLen; @@ -182,7 +182,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * @return $num Pseudo-random number * @todo I had a better random number generator here but now it is somewhere lost :( */ - public function randomNumber ($min, $max) { + public function randomNumber (int $min, int $max): int { return mt_rand($min, $max); } @@ -191,7 +191,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * * @return $extraSalt */ - public final function getExtraSalt () { + public final function getExtraSalt (): string { return $this->extraSalt; } @@ -200,7 +200,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * * @return $fixedSalt */ - public final function getFixedSalt () { + public final function getFixedSalt (): string { return $this->fixedSalt; } @@ -209,7 +209,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { * * @return $key The generated key for encryption */ - public function generateKey () { + public function generateKey (): string { // Default is extra salt $key = md5($this->getExtraSalt()); -- 2.39.5