From: Roland Häder Date: Sat, 7 Nov 2020 18:02:21 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f7795764503a5eba4ce861d8601c0707dd97778a;p=core.git Continued: - reduced monolithic BaseFrameworkSystem by moving $rngInstance, $imageInstance and $menuInstance with getter/setter to proper classes Signed-off-by: Roland Häder --- diff --git a/framework/config-global.php b/framework/config-global.php index 24eecc9e..1a3819e9 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -465,3 +465,12 @@ $cfg->setConfigEntry('thousands_separator', '.'); // CFG: DECIMALS-SEPARATOR $cfg->setConfigEntry('decimals_separator', ','); + +// CFG: CRYPTO-MCRYPT-STREAM-CLASS +$cfg->setConfigEntry('crypto_mcrypt_stream_class', 'Org\Mxchange\CoreFramework\Stream\Crypto\McryptStream'); + +// CFG: CRYPTO-OPENSSL-STREAM-CLASS +$cfg->setConfigEntry('crypto_openssl_stream_class', 'Org\Mxchange\CoreFramework\Stream\Crypto\OpenSslStream'); + +// CFG: CRYPTO-NULL-STREAM-CLASS +$cfg->setConfigEntry('crypto_null_stream_class', 'Org\Mxchange\CoreFramework\Stream\Crypto\NullCryptoStream'); diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 4aa523ab..3f68e5b8 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -8,7 +8,6 @@ use Org\Mxchange\CoreFramework\Criteria\Criteria; use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria; use Org\Mxchange\CoreFramework\Criteria\Local\LocalUpdateCriteria; use Org\Mxchange\CoreFramework\Crypto\Cryptable; -use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator; use Org\Mxchange\CoreFramework\Database\Frontend\DatabaseWrapper; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory; @@ -23,7 +22,6 @@ use Org\Mxchange\CoreFramework\Lists\Listable; use Org\Mxchange\CoreFramework\Loader\ClassLoader; use Org\Mxchange\CoreFramework\Localization\ManageableLanguage; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; -use Org\Mxchange\CoreFramework\Menu\RenderableMenu; use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult; @@ -107,11 +105,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac */ private $userInstance = NULL; - /** - * Instance of a RNG - */ - private $rngInstance = NULL; - /** * Instance of a crypto helper */ @@ -127,16 +120,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac */ private $listInstance = NULL; - /** - * Instance of a menu - */ - private $menuInstance = NULL; - - /** - * Instance of the image - */ - private $imageInstance = NULL; - /** * A helper instance for the form */ @@ -653,25 +636,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac return $this->userInstance; } - /** - * Setter for RNG instance - * - * @param $rngInstance An instance of a random number generator (RNG) - * @return void - */ - protected final function setRngInstance (RandomNumberGenerator $rngInstance) { - $this->rngInstance = $rngInstance; - } - - /** - * Getter for RNG instance - * - * @return $rngInstance An instance of a random number generator (RNG) - */ - public final function getRngInstance () { - return $this->rngInstance; - } - /** * Setter for Cryptable instance * @@ -710,44 +674,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac return $this->listInstance; } - /** - * Setter for the menu instance - * - * @param $menuInstance A RenderableMenu instance - * @return void - */ - protected final function setMenuInstance (RenderableMenu $menuInstance) { - $this->menuInstance = $menuInstance; - } - - /** - * Getter for the menu instance - * - * @return $menuInstance A RenderableMenu instance - */ - protected final function getMenuInstance () { - return $this->menuInstance; - } - - /** - * Setter for image instance - * - * @param $imageInstance An instance of an image - * @return void - */ - public final function setImageInstance (BaseImage $imageInstance) { - $this->imageInstance = $imageInstance; - } - - /** - * Getter for image instance - * - * @return $imageInstance An instance of an image - */ - public final function getImageInstance () { - return $this->imageInstance; - } - /** * Setter for DatabaseWrapper instance * diff --git a/framework/main/classes/crypto/class_CryptoHelper.php b/framework/main/classes/crypto/class_CryptoHelper.php index 96eb2f9d..7ef8d3f3 100644 --- a/framework/main/classes/crypto/class_CryptoHelper.php +++ b/framework/main/classes/crypto/class_CryptoHelper.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Helper\Crypto; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Crypto\Cryptable; +use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; @@ -50,6 +51,11 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ private $salt = ''; + /** + * Instance of a RNG + */ + private $rngInstance = NULL; + /** * Protected constructor * @@ -95,6 +101,25 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { return self::$selfInstance; } + /** + * Setter for RNG instance + * + * @param $rngInstance An instance of a random number generator (RNG) + * @return void + */ + protected final function setRngInstance (RandomNumberGenerator $rngInstance) { + $this->rngInstance = $rngInstance; + } + + /** + * Getter for RNG instance + * + * @return $rngInstance An instance of a random number generator (RNG) + */ + public final function getRngInstance () { + return $this->rngInstance; + } + /** * Attaches a crypto stream to this crypto helper by detecting loaded * modules. @@ -106,13 +131,13 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Do we have openssl/mcrypt loaded? if ($this->isPhpExtensionLoaded('mcrypt')) { // Then use it - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\McryptStream', array($this->getRngInstance())); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_mcrypt_stream_class', array($this->getRngInstance())); } elseif ($this->isPhpExtensionLoaded('openssl')) { // Then use it - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\OpenSslStream', array($this->getRngInstance())); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_openssl_stream_class', array($this->getRngInstance())); } else { // If nothing works ... - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\NullCryptoStream'); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_null_stream_class'); } } diff --git a/framework/main/classes/helper/captcha/class_BaseCaptcha.php b/framework/main/classes/helper/captcha/class_BaseCaptcha.php index 89dd8bc0..8005d064 100644 --- a/framework/main/classes/helper/captcha/class_BaseCaptcha.php +++ b/framework/main/classes/helper/captcha/class_BaseCaptcha.php @@ -3,6 +3,7 @@ namespace Org\Mxchange\CoreFramework\Helper\Captcha; // Import framework stuff +use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Helper\BaseHelper; @@ -30,6 +31,11 @@ use Org\Mxchange\CoreFramework\Helper\BaseHelper; * along with this program. If not, see . */ abstract class BaseCaptcha extends BaseHelper { + /** + * Instance of a RNG + */ + private $rngInstance = NULL; + /** * Protected constructor * @@ -41,6 +47,25 @@ abstract class BaseCaptcha extends BaseHelper { parent::__construct($className); } + /** + * Setter for RNG instance + * + * @param $rngInstance An instance of a random number generator (RNG) + * @return void + */ + protected final function setRngInstance (RandomNumberGenerator $rngInstance) { + $this->rngInstance = $rngInstance; + } + + /** + * Getter for RNG instance + * + * @return $rngInstance An instance of a random number generator (RNG) + */ + public final function getRngInstance () { + return $this->rngInstance; + } + /** * Initializes the random number generator (RNG) * diff --git a/framework/main/classes/response/image/class_ImageResponse.php b/framework/main/classes/response/image/class_ImageResponse.php index 8be1d27c..e6b7eff0 100644 --- a/framework/main/classes/response/image/class_ImageResponse.php +++ b/framework/main/classes/response/image/class_ImageResponse.php @@ -4,6 +4,7 @@ namespace Org\Mxchange\CoreFramework\Response; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; +use Org\Mxchange\CoreFramework\Image\BaseImage; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Response\Responseable; @@ -34,6 +35,11 @@ use Org\Mxchange\CoreFramework\Response\Responseable; * Michal Cihar , licensed under GNU GPL 2.0. */ class ImageResponse extends BaseResponse implements Responseable { + /** + * Instance of the image + */ + private $imageInstance = NULL; + /** * Protected constructor * @@ -60,6 +66,25 @@ class ImageResponse extends BaseResponse implements Responseable { return $responseInstance; } + /** + * Setter for image instance + * + * @param $imageInstance An instance of an image + * @return void + */ + public final function setImageInstance (BaseImage $imageInstance) { + $this->imageInstance = $imageInstance; + } + + /** + * Getter for image instance + * + * @return $imageInstance An instance of an image + */ + public final function getImageInstance () { + return $this->imageInstance; + } + /** * Initializes the template engine instance * diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index 85574487..e213c6a7 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Template\Engine; use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException; +use Org\Mxchange\CoreFramework\Image\BaseImage; use Org\Mxchange\CoreFramework\Parser\Xml\XmlParser; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Response\Responseable; @@ -74,6 +75,11 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl */ private $currMainNode = ''; + /** + * Instance of the image + */ + private $imageInstance = NULL; + /** * Protected constructor * @@ -163,6 +169,25 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl return $this->subNodes; } + /** + * Setter for image instance + * + * @param $imageInstance An instance of an image + * @return void + */ + public final function setImageInstance (BaseImage $imageInstance) { + $this->imageInstance = $imageInstance; + } + + /** + * Getter for image instance + * + * @return $imageInstance An instance of an image + */ + public final function getImageInstance () { + return $this->imageInstance; + } + /** * Handles the start element of an XML resource * @@ -220,7 +245,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl } // Construct method name - $methodName = 'finish' . StringUtils::convertToClassName($nodeName); + $methodName = sprintf('finish%s', StringUtils::convertToClassName($nodeName)); // Call the corresponding method call_user_func_array(array($this->getImageInstance(), $methodName), array()); @@ -499,6 +524,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl * * @param $responseInstance An instance of a Responseable class * @return void + * @todo Nothing to really "transfer" here? */ public function transferToResponse (Responseable $responseInstance) { // Set the image instance diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index 39177f1d..67fdedb9 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -113,11 +113,6 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla */ private $menuBlocks = array(); - /** - * Menu instance - */ - private $menuInstance = NULL; - /** * Current main node */ @@ -128,6 +123,11 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla */ private $dependencyContent = array(); + /** + * Instance of a menu + */ + private $menuInstance = NULL; + /** * Protected constructor * @@ -199,6 +199,25 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla return $templateInstance; } + /** + * Setter for the menu instance + * + * @param $menuInstance A RenderableMenu instance + * @return void + */ + protected final function setMenuInstance (RenderableMenu $menuInstance) { + $this->menuInstance = $menuInstance; + } + + /** + * Getter for the menu instance + * + * @return $menuInstance A RenderableMenu instance + */ + private final function getMenuInstance () { + return $this->menuInstance; + } + /** * Load a specified menu template into the engine *