From: Roland Häder Date: Sun, 6 Dec 2020 10:03:35 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2fe9cb99d3b4f2ea423a9205511fc50d64c2af8c;p=core.git Continued: - added type-hints for primitive variables - still a lot is left for refacturing ... Signed-off-by: Roland Häder --- diff --git a/framework/main/classes/factories/stacks/class_FileStackFactory.php b/framework/main/classes/factories/stacks/class_FileStackFactory.php index cc2060d8..7e4e1184 100644 --- a/framework/main/classes/factories/stacks/class_FileStackFactory.php +++ b/framework/main/classes/factories/stacks/class_FileStackFactory.php @@ -50,7 +50,7 @@ class FileStackFactory extends ObjectFactory { * @param $stackName Name of the stack * @return $stackInstance An instance of a StackableFile class */ - public static final function createFileStackInstance ($prefix, $stackName) { + public static final function createFileStackInstance (string $prefix, string $stackName) { // Construct file stack name $fileInfoInstance = new SplFileInfo(sprintf('%s%s/%s.%s', FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'), diff --git a/framework/main/classes/factories/xml/class_XmlTemplateEngineFactory.php b/framework/main/classes/factories/xml/class_XmlTemplateEngineFactory.php index 30ff41db..172550a6 100644 --- a/framework/main/classes/factories/xml/class_XmlTemplateEngineFactory.php +++ b/framework/main/classes/factories/xml/class_XmlTemplateEngineFactory.php @@ -49,7 +49,7 @@ class XmlTemplateEngineFactory extends ObjectFactory { * @param $configEntry Config entry name for the template engine * @return $templateInstance A template engine instance */ - public static final function createXmlTemplateEngineInstance ($configEntry) { + public static final function createXmlTemplateEngineInstance (string $configEntry) { // Do we have an instance in the registry? if (GenericRegistry::getRegistry()->instanceExists($configEntry)) { // Then use this instance diff --git a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php index 1588a795..b653dfb7 100644 --- a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php +++ b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php @@ -117,7 +117,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable { // Try to get real discovery class try { // Get an instance from the object factory - $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this)); + $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', [$this]); // Call the discovery method $discoveryInstance->discover($requestInstance); diff --git a/framework/main/classes/lists/class_BaseList.php b/framework/main/classes/lists/class_BaseList.php index b3135028..2a8595b1 100644 --- a/framework/main/classes/lists/class_BaseList.php +++ b/framework/main/classes/lists/class_BaseList.php @@ -82,7 +82,7 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate // Is the instance set? if (is_null($iteratorInstance)) { // Prepare a default iterator - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this)); + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', [$this]); // Set it here $this->setIteratorInstance($iteratorInstance); diff --git a/framework/main/classes/mailer/class_BaseMailer.php b/framework/main/classes/mailer/class_BaseMailer.php index 5e10bc19..885c3241 100644 --- a/framework/main/classes/mailer/class_BaseMailer.php +++ b/framework/main/classes/mailer/class_BaseMailer.php @@ -127,7 +127,7 @@ abstract class BaseMailer extends BaseFrameworkSystem { * @param $valueInstance An object instance which can provide "field values" * @return void */ - public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) { + public final function addValueInstance (string $variableName, FrameworkInterface $valueInstance) { $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance); } diff --git a/framework/main/classes/menu/class_BaseMenu.php b/framework/main/classes/menu/class_BaseMenu.php index f73d34e0..60b92f0b 100644 --- a/framework/main/classes/menu/class_BaseMenu.php +++ b/framework/main/classes/menu/class_BaseMenu.php @@ -56,7 +56,7 @@ abstract class BaseMenu extends BaseFrameworkSystem { */ public function renderMenu () { // Initialize the menu system by preparing it's template instance - $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this)); + $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', [$this]); // Set it for later use $this->setTemplateInstance($templateInstance); @@ -71,7 +71,7 @@ abstract class BaseMenu extends BaseFrameworkSystem { if (empty($command)) { // Use default page as none has been specified $command = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . ApplicationHelper::getSelfInstance()->getAppShortName() . '_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command'); - } // END - if + } // Load the menu template for this page try { diff --git a/framework/main/classes/registry/class_BaseRegistry.php b/framework/main/classes/registry/class_BaseRegistry.php index d7847063..f71e35c3 100644 --- a/framework/main/classes/registry/class_BaseRegistry.php +++ b/framework/main/classes/registry/class_BaseRegistry.php @@ -67,7 +67,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg // Is it set? if (is_null($this->getIteratorInstance())) { // Then instance it - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('registry_iterator_class', array($this)); + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('registry_iterator_class', [$this]); // ... and set it here $this->setIteratorInstance($iteratorInstance); @@ -89,7 +89,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $instanceKey The key holding an instance in registry * @return $exists Whether the key exists in registry */ - public function instanceExists ($instanceKey) { + public function instanceExists (string $instanceKey) { // Does this key exists? $exists = $this->isGenericArrayKeySet('registry', 'instance', $instanceKey); @@ -104,7 +104,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $objectInstance An instance we shall store * @return void */ - public function addInstance ($instanceKey, Registerable $objectInstance) { + public function addInstance (string $instanceKey, Registerable $objectInstance) { $this->setGenericArrayKey('registry', 'instance', $instanceKey, $objectInstance); } @@ -134,10 +134,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $value The value to be stored * @return void */ - public final function addEntry ($key, $value) { - // Key must not be an array - assert(!is_array($key)); - + public final function addEntry (string $key, $value) { // Push it $this->pushValueToGenericArrayKey('registry', 'generic', $key, $value); } @@ -145,12 +142,10 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg /** * Getter for entries or "sub entries" * + * @param $key Key * @return $entries An array with entries from this registry */ - public final function getEntries ($key = NULL) { - // Key must not be an array - assert(!is_array($key)); - + public final function getEntries (string $key = NULL) { // Default is whole array $entries = $this->getGenericArray('registry'); @@ -158,7 +153,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg if (!is_null($key)) { // Then use this entry $entries = $this->getGenericArrayKey('registry', 'generic', $key); - } // END - if + } // Return the array return $entries; @@ -171,59 +166,44 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $lookFor The key to look for * @return $entry An array with all keys */ - public function getArrayFromKey ($arrayKey, $lookFor) { - // Key must not be an array - assert(!is_array($arrayKey)); - + public function getArrayFromKey (string $arrayKey, string $lookFor) { // Init array $entry = []; - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking arrayKey=' . $arrayKey . ',lookFor=' . $lookFor); - // "Walk" over all entries + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking arrayKey=' . $arrayKey . ',lookFor=' . $lookFor); foreach ($this->getEntries($arrayKey) as $key => $value) { - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',value=' . $value . ',lookFor=' . $lookFor); - // If $value matches the $lookFor, we need to look for more entries for this! + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',value=' . $value . ',lookFor=' . $lookFor); if ($lookFor == $value) { // Look for more entries foreach ($this->getEntries() as $key2 => $value2) { // Now "walk" through all entries, if an array is returned if (is_array($value2)) { - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key2=' . $key2 . ',value2()=' . count($value2) . ',lookFor=' . $lookFor); - // "Walk" through all of them + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key2=' . $key2 . ',value2()=' . count($value2) . ',lookFor=' . $lookFor); foreach ($value2 as $key3 => $value3) { // $value3 needs to be an array assert(is_array($value3)); - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',key3=' . $key3 . ',isset()=' . isset($value3[$key]) . ' ...'); - // Both keys must match! + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',key3=' . $key3 . ',isset()=' . isset($value3[$key]) . ' ...'); if (($key == $key3) || (isset($value3[$key]))) { - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Adding ' . $value3[$key] . ' ...'); - // Then add it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Adding ' . $value3[$key] . ' ...'); $entry[$key3] = $value3[$key]; - } // END - if - } // END - foreach - } // END - if - } // END - foreach + } + } + } + } // Skip further lookups break; - } // END - if - } // END - foreach - - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Returning entry(' . count($entry) . ')=' . print_r($entry, true)); + } + } // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Returning entry(' . count($entry) . ')=' . print_r($entry, true)); return $entry; } @@ -234,12 +214,12 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @return $objectInstance An instance we shall store * @throws NullPointerException If the requested key is not found */ - public function getInstance ($instanceKey) { + public function getInstance (string $instanceKey) { // Is the instance there? if (!$this->instanceExists($instanceKey)) { // This might happen if a non-registered key was requested throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } // END - if + } // Get the instance $objectInstance = $this->getGenericArrayKey('registry', 'instance', $instanceKey); @@ -257,7 +237,7 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $data An array with data * @return $registryKey A registry key */ - public static function getRegistryKeyFromArray ($prefix, array $data) { + public static function getRegistryKeyFromArray (string $prefix, array $data) { // "Generate" the key $registryKey = $prefix . self::REGISTRY_KEY_GLUE . implode(self::REGISTRY_KEY_GLUE, $data); diff --git a/framework/main/classes/resolver/action/class_BaseActionResolver.php b/framework/main/classes/resolver/action/class_BaseActionResolver.php index 3578fb3d..443b1147 100644 --- a/framework/main/classes/resolver/action/class_BaseActionResolver.php +++ b/framework/main/classes/resolver/action/class_BaseActionResolver.php @@ -131,7 +131,7 @@ abstract class BaseActionResolver extends BaseResolver { $this->setClassName($className); // Initiate the action - $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); + $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), [$this]); // Return the result return $actionInstance; diff --git a/framework/main/classes/resolver/command/class_BaseCommandResolver.php b/framework/main/classes/resolver/command/class_BaseCommandResolver.php index 9d5177aa..8287891f 100644 --- a/framework/main/classes/resolver/command/class_BaseCommandResolver.php +++ b/framework/main/classes/resolver/command/class_BaseCommandResolver.php @@ -103,7 +103,7 @@ abstract class BaseCommandResolver extends BaseResolver { } // Initiate the command - $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); + $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), [$this]); // Return the result return $commandInstance; diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index 925c96bf..da1faf41 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -298,7 +298,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $className = StringUtils::convertToClassName($imageType.'_image'); // And try to initiate it - $this->setImageInstance(ObjectFactory::createObjectByName($className, array($this))); + $this->setImageInstance(ObjectFactory::createObjectByName($className, [$this])); // Set current main node to type $this->currMainNode = 'type'; diff --git a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php index 253e0a8a..39026824 100644 --- a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php +++ b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php @@ -374,7 +374,7 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi } // Get a XmlParser instance - $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this)); + $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', [$this]); // Check if XML compacting is enabled if ($this->isXmlCompactingEnabled()) { diff --git a/framework/main/interfaces/registry/class_Register.php b/framework/main/interfaces/registry/class_Register.php index 03622cd9..26b5ef48 100644 --- a/framework/main/interfaces/registry/class_Register.php +++ b/framework/main/interfaces/registry/class_Register.php @@ -34,7 +34,7 @@ interface Register extends FrameworkInterface { * @param $instanceKey The key holding an instance in registry * @return $exists Whether the key exists in registry */ - function instanceExists ($instanceKey); + function instanceExists (string $instanceKey); /** * Adds/overwrites a new instance to the registry at the given key @@ -43,7 +43,7 @@ interface Register extends FrameworkInterface { * @param $objectInstance An instance we shall store * @return void */ - function addInstance ($instanceKey, Registerable $objectInstance); + function addInstance (string $instanceKey, Registerable $objectInstance); /** * Getter for whole generic registry @@ -67,14 +67,14 @@ interface Register extends FrameworkInterface { * @param $value The value to be stored * @return void */ - function addEntry ($key, $value); + function addEntry (string $key, $value); /** * Getter for entries or "sub entries" * * @return $entries An array with entries from this registry */ - function getEntries ($key = NULL); + function getEntries (string $key = NULL); /** * "Getter" for an array of all entries for given key @@ -83,7 +83,7 @@ interface Register extends FrameworkInterface { * @param $lookFor The key to look for * @return $entry An array with all keys */ - function getArrayFromKey ($arrayKey, $lookFor); + function getArrayFromKey (string $arrayKey, string $lookFor); /** * Gets a registered instance or null if not found @@ -92,6 +92,6 @@ interface Register extends FrameworkInterface { * @return $objectInstance An instance we shall store * @throws NullPointerException If the requested key is not found */ - function getInstance ($instanceKey); + function getInstance (string $instanceKey); }