From: Roland Häder Date: Sun, 23 Jun 2013 03:32:52 +0000 (+0000) Subject: Fixes and double->single converted X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=89f25725096fa51850e2d4d0a2ed57906c0b23e0 Fixes and double->single converted --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 4d354301..d146ed4b 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -193,6 +193,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $packageData = array(); + /** + * Generic array + */ + private $genericArray = array(); + /*********************** * Exception codes.... * ***********************/ @@ -2109,6 +2114,324 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // ... and return it return $isset; } + + /** + * Determines if a key is set in the generic array + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to check + * @return $isset Whether the given key is set + */ + protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) { + // Is it there? + $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]); + + // Return it + return $isset; + } + + /** + * Determines if an element is set in the generic array + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to check + * @param $element Element to check + * @return $isset Whether the given key is set + */ + protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) { + // Is it there? + $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]); + + // Return it + return $isset; + } + + /** + * Determines if a group is set in the generic array + * + * @param $keyGroup Main group + * @param $subGroup Sub group + * @return $isset Whether the given group is set + */ + protected final function isGenericArrayGroupSet ($keyGroup, $subGroup) { + // Is it there? + $isset = isset($this->genericArray[$keyGroup][$subGroup]); + + // Return it + return $isset; + } + + /** + * Getter for sub key group + * + * @param $keyGroup Main key group + * @param $subGroup Sub key group + * @return $array An array with all array elements + */ + protected final function getGenericSubArray ($keyGroup, $subGroup) { + // Is it there? + if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) { + // No, then abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.'); + } // END - if + + // Return it + return $this->genericArray[$keyGroup][$subGroup]; + } + + /** + * Unsets a given key in generic array + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to unset + * @return void + */ + protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key) { + // Remove it + unset($this->genericArray[$keyGroup][$subGroup][$key]); + } + + /** + * Append a string to a given generic array key + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to unset + * @param $value Value to add/append + * @return void + */ + protected final function appendStringToGenericArrayElement ($keyGroup, $subGroup, $key, $value, $appendGlue = '') { + // Is it already there? + if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) { + // Append it + $this->genericArray[$keyGroup][$subGroup][$key] .= $appendGlue . (string) $value; + } else { + // Add it + $this->genericArray[$keyGroup][$subGroup][$key] = (string) $value; + } + } + + /** + * Pushes an element to a generic key + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to use + * @param $value Value to add/append + * @return $count Number of array elements + */ + protected final function pushValueToGenericArrayElement ($keyGroup, $subGroup, $key, $value) { + // Is it set? + if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) { + // Initialize array + $this->genericArray[$keyGroup][$subGroup][$key] = array(); + } // END - if + + // Then push it + $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value); + + // Return count + return $count; + } + + /** + * Sets a value in given generic array key/element + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to set + * @param $element Element to set + * @param $value Value to set + * @return void + */ + protected final function setGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value) { + // Then set it + $this->genericArray[$keyGroup][$subGroup][$key][$element] = $value; + } + + /** + * Pops an element from a generic group + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to unset + * @return $value Last "popped" value + */ + protected final function popGenericArrayElement ($keyGroup, $subGroup, $key) { + // Is it set? + if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) { + // Not found + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.'); + } // END - if + + // Then "pop" it + $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]); + + // Return value + return $value; + } + + /** + * Shifts an element from a generic group + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @param $key Key to unset + * @return $value Last "popped" value + */ + protected final function shiftGenericArrayElement ($keyGroup, $subGroup, $key) { + // Is it set? + if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) { + // Not found + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.'); + } // END - if + + // Then "shift" it + $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]); + + // Return value + return $value; + } + + /** + * Count generic array group + * + * @param $keyGroup Main group for the key + * @return $count Count of given group + */ + protected final function countGenericArray ($keyGroup) { + // Is it there? + if (!isset($this->genericArray[$keyGroup])) { + // Abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.'); + } // END - if + + // Then count it + $count = count($this->genericArray[$keyGroup]); + + // Return it + return $count; + } + + /** + * Count generic array sub group + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @return $count Count of given group + */ + protected final function countGenericArrayGroup ($keyGroup, $subGroup) { + // Is it there? + if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) { + // Abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.'); + } // END - if + + // Then count it + $count = count($this->genericArray[$keyGroup][$subGroup]); + + // Return it + return $count; + } + + /** + * Count generic array elements + * + * @param $keyGroup Main group for the key + * @param $subGroup Sub group for the key + * @para $key Key to count + * @return $count Count of given key + */ + protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) { + // Is it there? + if (!$this->isGenericArrayKeySet($keyGroup, $subGroup)) { + // Abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.'); + } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) { + // Not valid + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.'); + } + + // Then count it + $count = count($this->genericArray[$keyGroup][$subGroup][$key]); + + // Return it + return $count; + } + + /** + * Getter for whole generic group array + * + * @param $keyGroup Key group to get + * @return $array Whole generic array group + */ + protected final function getGenericArray ($keyGroup) { + // Is it there? + if (!isset($this->genericArray[$keyGroup])) { + // Then abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.'); + } // END - if + + // Return it + return $this->genericArray[$keyGroup]; + } + + /** + * Getter for generic array key + * + * @param $keyGroup Key group to get + * @param $subGroup Sub group for the key + * @param $key Key to unset + * @return $value Mixed value from generic array element + */ + protected final function getGenericArrayKey ($keyGroup, $subGroup, $key) { + // Is it there? + if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) { + // Then abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.'); + } // END - if + + // Return it + return $this->genericArray[$keyGroup][$subGroup][$key]; + } + + /** + * Getter for generic array element + * + * @param $keyGroup Key group to get + * @param $subGroup Sub group for the key + * @param $key Key to look for + * @param $element Element to look for + * @return $value Mixed value from generic array element + */ + protected final function getGenericArrayElement ($keyGroup, $subGroup, $key, $element) { + // Is it there? + if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) { + // Then abort here + trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.'); + } // END - if + + // Return it + return $this->genericArray[$keyGroup][$subGroup][$key][$element]; + } + + /** + * Checks if a given sub group is valid (array) + * + * @param $keyGroup Key group to get + * @param $subGroup Sub group for the key + * @return $isValid Whether given sub group is valid + */ + protected final function isValidGenericArrayGroup ($keyGroup, $subGroup) { + // Determine it + $isValid = (($this->isGenericArrayGroupSet($keyGroup, $subGroup)) && (is_array($this->getGenericSubArray($keyGroup, $subGroup)))); + + // Return it + return $isValid; + } } // [EOF] diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php index cbf192d3..dfa0d4ee 100644 --- a/inc/classes/main/criteria/class_BaseCriteria.php +++ b/inc/classes/main/criteria/class_BaseCriteria.php @@ -27,18 +27,6 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { */ private $wrapperConfigEntry = ''; - /** - * Criteria to handle - */ - private $criteria = array( - // Default - 'default' => array(), - // Choice - 'choice' => array(), - // .. and exclude - 'exclude' => array(), - ); - /** * Protected constructor * @@ -62,7 +50,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE)); // Determine it - $isSet = isset($this->criteria[$criteriaType][$criteriaKey]); + $isSet = $this->isGenericArrayKeySet('criteria', $criteriaType, $criteriaKey); // Return it return $isSet; @@ -116,7 +104,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { * @return $criteria */ public final function getCriteriaArray ($criteriaType = 'default') { - return $this->criteria[$criteriaType]; + return $this->getGenericSubArray('criteria', $criteriaType); } /** @@ -151,9 +139,9 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $criteriaKey = $this->convertDashesToUnderscores($criteriaKey); // "Walk" through all criterias - foreach ($this->criteria as $criteriaType => $dummy) { + foreach ($this->getGenericArray('criteria') as $criteriaType => $dummy) { // Remove it - unset($this->criteria[$criteriaType][$criteriaKey]); + $this->unsetGenericArrayElement('criteria', $criteriaType, $criteriaKey); } // END - foreach } @@ -176,14 +164,8 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue); - // Is it already there? - if ($this->isKeySet($criteriaType, $criteriaKey)) { - // Append it - $this->criteria[$criteriaType][$criteriaKey] .= ',' . (string) $criteriaValue; - } else { - // Add it - $this->criteria[$criteriaType][$criteriaKey] = (string) $criteriaValue; - } + // Append it + $this->appendStringToGenericArrayElement('criteria', $criteriaType, $criteriaKey, $criteriaValue); } /** @@ -202,7 +184,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue); // Add it - array_push($this->criteria['choice'][$this->convertDashesToUnderscores($criteriaKey)], (string) $criteriaValue); + $this->pushValueToGenericArrayElement('criteria', 'choice', $this->convertDashesToUnderscores($criteriaKey), (string) $criteriaValue); } /** @@ -247,7 +229,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $criteriaKey = $this->convertDashesToUnderscores($criteriaKey); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . count($this->criteria[$criteriaType])); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . $this->countGenericArrayGroup('criteria', $criteriaType))); // Default is not found $value = FALSE; @@ -255,7 +237,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { // Is the criteria there? if ($this->isKeySet($criteriaType, $criteriaKey)) { // Then use it - $value = $this->criteria[$criteriaType][$criteriaKey]; + $value = $this->getGenericArrayKey('criteria', $criteriaType, $criteriaKey); } // END - if // Return the value @@ -305,7 +287,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $key = $this->convertDashesToUnderscores($key); // Then walk through all search criteria - foreach ($this->criteria[$criteriaType] as $criteriaKey => $criteriaValue) { + foreach ($this->getGenericSubArray('criteria', $criteriaType) as $criteriaKey => $criteriaValue) { // Make sure no 'my-' or 'my_' passes this point assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue))); @@ -321,7 +303,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { } // END - foreach // Now check if expected criteria counts match - $matches = ($counted == count($this->criteria[$criteriaType])); + $matches = ($counted == $this->countGenericArrayGroup('criteria', $criteriaType))); // Return the result return $matches; @@ -358,16 +340,16 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { */ public function getCacheKey ($onlyKeys = array(), $criteriaType = 'default') { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': criteriaType=' . $criteriaType . ',count()=' . count($this->criteria)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': criteriaType=' . $criteriaType . ',count()=' . $this->countGenericArray('criteria'))); // Make sure the criteria is there - assert((isset($this->criteria[$criteriaType])) && (is_array($this->criteria[$criteriaType]))); + assert($this->isValidGenericArrayGroup('criteria', $criteriaType)); // Initialize the key $cacheKey = ''; // Now walk through all criterias - foreach ($this->criteria[$criteriaType] as $criteriaKey => $criteriaValue) { + foreach ($this->getGenericSubArray('criteria', $criteriaType) as $criteriaKey => $criteriaValue) { // Make sure no 'my-' or 'my_' passes this point assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue))); @@ -434,7 +416,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { */ public final function count ($criteriaType = 'default') { // Return it - return count($this->criteria[$criteriaType]); + return $this->countGenericArrayGroup('criteria', $criteriaType)); } /** diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php index c192bf3f..ef173181 100644 --- a/inc/classes/main/filter/class_FilterChain.php +++ b/inc/classes/main/filter/class_FilterChain.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class FilterChain extends BaseFrameworkSystem implements Registerable { - /** - * All filters together - */ - private $filters = array(); - /** * Protected constructor * @@ -57,7 +52,7 @@ class FilterChain extends BaseFrameworkSystem implements Registerable { * @return void */ public final function addFilter (Filterable $filterInstance) { - array_push($this->filters, $filterInstance); + $this->pushValueToGenericArrayElement('filters', 'generic', 'dummy', $filterInstance); } /** @@ -66,7 +61,7 @@ class FilterChain extends BaseFrameworkSystem implements Registerable { * @return $filters The filters array holding all filter instances */ protected function getFilters () { - return $this->filters; + return $this->getGenericArray('filters'); } /** @@ -78,7 +73,7 @@ class FilterChain extends BaseFrameworkSystem implements Registerable { */ public function processFilters (Requestable $requestInstance, Responseable $responseInstance) { // Run all filters - //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('COUNT=' . count($this->filters)); + //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('COUNT=' . $this->countGenericArray('filters')); foreach ($this->getFilters() as $filterInstance) { // Try to execute this filter try { diff --git a/inc/classes/main/mailer/class_BaseMailer.php b/inc/classes/main/mailer/class_BaseMailer.php index ffd0bc15..9d9b1212 100644 --- a/inc/classes/main/mailer/class_BaseMailer.php +++ b/inc/classes/main/mailer/class_BaseMailer.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class BaseMailer extends BaseFrameworkSystem { - /** - * Iterateable list of recipients - */ - private $recipientList = array(); - /** * Template name */ @@ -73,19 +68,13 @@ class BaseMailer extends BaseFrameworkSystem { $templateName = $this->getTemplateName(); // Is the list initialized? - if (!isset($this->recipientList[$templateName]['recipients'])) { - // Then initialize it here - $this->recipientList[$templateName]['recipients'] = array(); - } // END - if - - // Add it as a recipient - array_pushh($this->recipientList[$templateName]['recipients'], $userInstance); + $this->pushValueToGenericArrayElement('recipients', $templateName, 'recipients', $userInstance); } /** * Adds a template variable (just the name) to the recipient list in given section of current template * - * @param $section Section can be "config" or "value" currently + * @param $section Section can be 'config' or "value" currently * @param $variableName Template variable name to add * @return void */ @@ -97,13 +86,7 @@ class BaseMailer extends BaseFrameworkSystem { $sectionName = $section . '_vars'; // Is the list initialized? - if (!isset($this->recipientList[$templateName][$sectionName])) { - // Then initialize it here - $this->recipientList[$templateName][$sectionName] = array(); - } // END - if - - // Add the variable to the list - $this->recipientList[$templateName][$sectionName][$variableName] = 'OK'; + $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK'); } /** @@ -113,17 +96,17 @@ class BaseMailer extends BaseFrameworkSystem { * @return void */ public final function addConfigTemplateVariable ($variableName) { - $this->addTemplateVariable("config", $variableName); + $this->addTemplateVariable('config', $variableName); } /** - * Adds a "value" template variable to the recipient list of current template + * Adds a 'value' template variable to the recipient list of current template * * @param $variableName Template variable name to add * @return void */ public final function addValueTemplateVariable ($variableName) { - $this->addTemplateVariable("value", $variableName); + $this->addTemplateVariable('value', $variableName); } /** @@ -134,7 +117,7 @@ class BaseMailer extends BaseFrameworkSystem { * @return void */ public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) { - $this->recipientList[$this->getTemplateName()]['values'][$variableName] = $valueInstance; + $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance); } /** @@ -163,7 +146,7 @@ class BaseMailer extends BaseFrameworkSystem { * @return void */ public final function setSubjectLine ($subjectLine) { - $this->recipientList[$this->getTemplateName()]['subject'] = (string) $subjectLine; + ` $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine); } /** @@ -179,9 +162,9 @@ class BaseMailer extends BaseFrameworkSystem { $templateName = $this->getTemplateName(); // Does the subject line exist? - if ((!empty($templateName)) && (isset($this->recipientList[$templateName]['subject']))) { + if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject']))) { // Then use it - $subjectLine = $this->recipientList[$templateName]['subject']; + $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject'); } // END - if // Return it @@ -204,7 +187,7 @@ class BaseMailer extends BaseFrameworkSystem { * @return $recipientList Array with reciepients */ public final function getRecipientList () { - return $this->recipientList; + return $this->getGenericArray('recipients'); } } diff --git a/inc/classes/main/registry/class_BaseRegistry.php b/inc/classes/main/registry/class_BaseRegistry.php index c9a80904..df0f9798 100644 --- a/inc/classes/main/registry/class_BaseRegistry.php +++ b/inc/classes/main/registry/class_BaseRegistry.php @@ -32,16 +32,6 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { */ private static $registryInstance = NULL; - /** - * Instance registry - */ - private $instanceRegistry = array(); - - /** - * Raw data entries (non-objects) - */ - private $rawEntries = array(); - /** * Protected constructor * @@ -61,7 +51,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { */ public function instanceExists ($instanceKey) { // Does this key exists? - $exists = (isset($this->instanceRegistry[$instanceKey])); + $exists = $this->isGenericArrayKeySet('registry', 'instance', $instanceKey); // Return the result return $exists; @@ -75,7 +65,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { * @return void */ public function addInstance ($instanceKey, Registerable $objectInstance) { - $this->instanceRegistry[$instanceKey] = $objectInstance; + $this->pushValueToGenericArrayElement('registry', 'instance', $instanceKey, $objectInstance); } /** @@ -84,7 +74,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { * @return $instanceRegistry The whole instance registry array */ public final function getInstanceRegistry () { - return $this->instanceRegistry; + return $this->getGenericSubArray('registry', 'instance'); } /** @@ -96,14 +86,8 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { * @return void */ public final function addEntry ($key, $value) { - // Is the array there? - if (!isset($this->rawEntries[$key])) { - // Then intialize it here - $this->rawEntries[$key] = array(); - } // END - if - - // Simply add it - array_push($this->rawEntries[$key], $value); + // Push it + $this->pushValueToGenericArrayElement('raw', 'generic', $key, $value); } /** @@ -113,12 +97,12 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { */ public final function getEntries ($key = NULL) { // Default is whole array - $entries = $this->rawEntries; + $entries = $this->getGenericArray('raw'); // Is $key set? - if ((!is_null($key)) && (isset($this->rawEntries[$key]))) { + if (!is_null($key)) { // Then use this entry - $entries = $this->rawEntries[$key]; + $entries = $this->getGenericArrayKey('raw', 'generic', $key); } // END - if // Return the array @@ -182,7 +166,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable { } // END - if // Get the instance - $objectInstance = $this->instanceRegistry[$instanceKey]; + $objectInstance = $this->getGenericArrayKey('registry', 'instance', $instanceKey); // Return the result return $objectInstance; diff --git a/inc/classes/main/response/class_BaseResponse.php b/inc/classes/main/response/class_BaseResponse.php index 6eb3e238..a2d0e302 100644 --- a/inc/classes/main/response/class_BaseResponse.php +++ b/inc/classes/main/response/class_BaseResponse.php @@ -50,11 +50,6 @@ class BaseResponse extends BaseFrameworkSystem { */ private $templateInstance = NULL; - /** - * Fatal resolved messages from filters and so on - */ - private $fatalMessages = array(); - /** * Protected constructor * @@ -125,7 +120,7 @@ class BaseResponse extends BaseFrameworkSystem { */ public final function addFatalMessage ($messageId) { // Adds the resolved message id to the fatal message list - array_push($this->fatalMessages, $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId)); + $this->addFatalMessagePlain($this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId)); } /** @@ -136,7 +131,7 @@ class BaseResponse extends BaseFrameworkSystem { */ public final function addFatalMessagePlain ($message) { // Adds the resolved message id to the fatal message list - array_push($this->fatalMessages, $message); + $this->pushValueToGenericArrayElement('fatal_messages', 'generic', 'message', $message); } /** @@ -186,12 +181,12 @@ class BaseResponse extends BaseFrameworkSystem { } // Are there some error messages? - if (count($this->fatalMessages) == 0) { + if ($this->countGenericArrayElements('fatal_messages', 'generic', 'message') == 0) { // Flush the output to the world $this->getWebOutputInstance()->output($this->responseBody); } else { // Display all error messages - $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); + $this->getApplicationInstance()->handleFatalMessages($this->getGenericArrayKey('fatal_messages', 'generic', 'message')); // Send the error messages out to the world $this->getWebOutputInstance()->output($this->responseBody); diff --git a/inc/classes/main/stacker/class_BaseStacker.php b/inc/classes/main/stacker/class_BaseStacker.php index 147ae9d8..40f7c051 100644 --- a/inc/classes/main/stacker/class_BaseStacker.php +++ b/inc/classes/main/stacker/class_BaseStacker.php @@ -28,11 +28,6 @@ class BaseStacker extends BaseFrameworkSystem { const EXCEPTION_NO_STACKER_FOUND = 0x052; const EXCEPTION_STACKER_IS_EMPTY = 0x053; - /** - * An array holding all stacks - */ - private $stacks = array(); - /** * Protected constructor * @@ -60,10 +55,7 @@ class BaseStacker extends BaseFrameworkSystem { } // END - if // Initialize the given stack - $this->stacks[$stackerName] = array( - 'max_size' => $this->getConfigInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size'), - 'entries' => array() - ); + $this->pushValueToGenericArrayElement('stacks', $stackerName, 'max_size', $this->getConfigInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size')); } /** @@ -74,7 +66,7 @@ class BaseStacker extends BaseFrameworkSystem { */ public final function isStackInitialized ($stackerName) { // Is is there? - $isInitialized = ((isset($this->stacks[$stackerName])) && (is_array($this->stacks[$stackerName]))); + $isInitialized = ($this->isValidGenericArrayGroup('stacks', $stackerName)); // Return result return $isInitialized; @@ -137,7 +129,7 @@ class BaseStacker extends BaseFrameworkSystem { } // END - if // Now, count the array of entries - $count = count($this->stacks[$stackerName]['entries']); + $count = $this->countGenericArrayElements('stacks', $stackerName, 'entries'); // Return result return $count; @@ -162,7 +154,7 @@ class BaseStacker extends BaseFrameworkSystem { } // Now add the value to the stack - array_push($this->stacks[$stackerName]['entries'], $value); + $this->pushValueToGenericArrayElement('stacks', $stackerName, 'entries', $value); } /** @@ -184,7 +176,7 @@ class BaseStacker extends BaseFrameworkSystem { } // Now get the last value - $value = $this->stacks[$stackerName]['entries'][$this->getStackCount($stackerName) - 1]; + $value = $this->getGenericArrayKey('stacks', $stackerName, 'entries', $this->getStackCount($stackerName) - 1); // Return it return $value; @@ -208,8 +200,8 @@ class BaseStacker extends BaseFrameworkSystem { throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); } - // Now get the last value - $value = $this->stacks[$stackerName]['entries'][0]; + // Now get the first value + $value = $this->getGenericArrayKey('stacks', $stackerName, 'entries', 0); // Return it return $value; @@ -234,7 +226,7 @@ class BaseStacker extends BaseFrameworkSystem { } // Now, remove the last entry, we don't care about the return value here, see elseif() block above - array_pop($this->stacks[$stackerName]['entries']); + $this->popGenericArrayElement('stacks', $stackerName, 'entries'); } /** @@ -256,7 +248,7 @@ class BaseStacker extends BaseFrameworkSystem { } // Now, remove the last entry, we don't care about the return value here, see elseif() block above - array_shift($this->stacks[$stackerName]['entries']); + $this->shiftGenericArrayElement('stacks', $stackerName, 'entries'); } } diff --git a/inc/classes/third_party/api/wernisportal/class_WernisApi.php b/inc/classes/third_party/api/wernisportal/class_WernisApi.php index 5600032c..9e863a6a 100644 --- a/inc/classes/third_party/api/wernisportal/class_WernisApi.php +++ b/inc/classes/third_party/api/wernisportal/class_WernisApi.php @@ -7,6 +7,7 @@ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org + * @todo Out-dated since 0.6-BETA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -116,7 +117,7 @@ class WernisApi extends BaseFrameworkSystem { $amount = isset($amount) ? $amount+0 : 0; if ($amount < $this->config['mineinsatz']) { - $this->setStatusMessage('low_stakes', sprintf("Dein Einsatz muss mindestens %d Wernis betragen.", $this->config['mineinsatz'])); + $this->setStatusMessage('low_stakes', sprintf('Dein Einsatz muss mindestens %d Wernis betragen.', $this->config['mineinsatz'])); return false; } @@ -129,7 +130,7 @@ class WernisApi extends BaseFrameworkSystem { $amount = isset($amount) ? $amount+0 : 0; if ($amount < $this->config['mineinsatz']) { - $this->setStatusMessage('low_stakes', sprintf("Dein Einsatz muss mindestens %d Wernis betragen.", $this->config['mineinsatz'])); + $this->setStatusMessage('low_stakes', sprintf('Dein Einsatz muss mindestens %d Wernis betragen.', $this->config['mineinsatz'])); return false; } @@ -140,8 +141,8 @@ class WernisApi extends BaseFrameworkSystem { // Script abbrechen mit Zurueck-Buttom public function ende () { global $_CONFIG; - include "templates/zurueck.html"; - include "templates/fuss.html"; + include 'templates/zurueck.html'; + include 'templates/fuss.html'; exit(); } @@ -164,7 +165,7 @@ class WernisApi extends BaseFrameworkSystem { return $this->statusArray['message']; } else { // Fall-back to status - return sprintf("Fehler-Code %s ist keiner Nachricht zugewiesen.", $this->getErrorCode()); + return sprintf('Fehler-Code %s ist keiner Nachricht zugewiesen.', $this->getErrorCode()); } } @@ -185,8 +186,8 @@ class WernisApi extends BaseFrameworkSystem { if (!is_array($requestData)) { // Then abort here! return array( - 'status' => "failed_general", - 'message' => "API-Daten in config sind ungültig!" + 'status' => 'failed_general', + 'message' => 'API-Daten in config sind ungültig!' ); } @@ -194,13 +195,13 @@ class WernisApi extends BaseFrameworkSystem { if ((empty($this->config['wernis_api_id'])) || (empty($this->config['wernis_api_key']))) { // Abort here... return array( - 'status' => "failed_general", - 'message' => "API-Daten in config.php sind leer!" + 'status' => 'failed_general', + 'message' => 'API-Daten in config.php sind leer!' ); } // Construct the request string - $requestString = $this->config['api_url'] . $scriptName."?api_id=".$this->config['wernis_api_id']."&api_key=".$this->config['wernis_api_key']; + $requestString = $this->config['api_url'] . $scriptName . '?api_id=' . $this->config['wernis_api_id'] . '&api_key='.$this->config['wernis_api_key']; foreach ($requestData as $key => $value) { $requestString .= '&' . $key . '=' . $value; } @@ -212,8 +213,8 @@ class WernisApi extends BaseFrameworkSystem { if (strpos($response[0], '200') === FALSE) { // Something bad happend... :( return array( - 'status' => "request_error", - 'message' => sprintf("Servermeldung %s von WDS66-API erhalten.", $response[0]) + 'status' => 'request_error', + 'message' => sprintf('Servermeldung %s von WDS66-API erhalten.', $response[0]) ); } @@ -239,51 +240,51 @@ class WernisApi extends BaseFrameworkSystem { $return = array(); // We use only the first two entries (which shall be fine) - if ($data[0] === "error") { + if ($data[0] === 'error') { // The request has failed... :( switch ($data[1]) { - case "404": // Invalid API ID - case "AUTH": // Authorization has failed + case '404': // Invalid API ID + case 'AUTH': // Authorization has failed $return = array( - 'status' => "auth_failed", - 'message' => "API-Daten scheinen nicht zu stimmen! (Access Denied)" + 'status' => 'auth_failed', + 'message' => 'API-Daten scheinen nicht zu stimmen! (Access Denied)' ); break; - case "LOCKED": // User account is locked! - case "PASS": // Bad passphrase entered - case "USER": // Missing account or invalid password + case 'LOCKED': // User account is locked! + case 'PASS': // Bad passphrase entered + case 'USER': // Missing account or invalid password $return = array( - 'status' => "user_failed", - 'message' => "Dein eingegebener WDS66-Username stimmt nicht, ist gesperrt oder du hast ein falsches Passwort eingegeben." + 'status' => 'user_failed', + 'message' => 'Dein eingegebener WDS66-Username stimmt nicht, ist gesperrt oder du hast ein falsches Passwort eingegeben.' ); break; - case "OWN": // Transfer to own account + case 'OWN': // Transfer to own account $return = array( - 'status' => "own_failed", - 'message' => "Du darfst dein eigenes Spiel leider nicht spielen." + 'status' => 'own_failed', + 'message' => 'Du darfst dein eigenes Spiel leider nicht spielen.' ); break; - case "AMOUNT": // Amount is depleted + case 'AMOUNT': // Amount is depleted $return = array( - 'status' => "amount_failed", - 'message' => "Dein Guthaben reicht nicht aus, um das Spiel zu spielen." + 'status' => 'amount_failed', + 'message' => 'Dein Guthaben reicht nicht aus, um das Spiel zu spielen.' ); break; - case "AMOUNT-SEND": // API amount is depleted + case 'AMOUNT-SEND': // API amount is depleted $return = array( - 'status' => "api_amount_failed", - 'message' => "Nicht genügend Guthaben auf dem API-Account." + 'status' => 'api_amount_failed', + 'message' => 'Nicht genügend Guthaben auf dem API-Account.' ); break; default: // Unknown error (maybe new?) $return = array( - 'status' => "request_failed", - 'message' => sprintf("Unbekannter Fehler %s von API erhalten.", $data[1]) + 'status' => 'request_failed', + 'message' => sprintf('Unbekannter Fehler %s von API erhalten.', $data[1]) ); break; } @@ -312,13 +313,13 @@ class WernisApi extends BaseFrameworkSystem { 'sub_request' => 'receive', 't_uid' => $this->w_id, 't_md5' => $this->w_md5, - 'r_uid' => (int)$this->config['wernis_refid'], - 'amount' => (int)$amount, + 'r_uid' => (int) $this->config['wernis_refid'], + 'amount' => (int) $amount, 'purpose' => urlencode(base64_encode($purpose)) ); // Return the result from the lower functions - $return = $this->sendRequest("book.php", $requestData); + $return = $this->sendRequest('book.php', $requestData); if ($return['status'] == $this->statusOkay) { // All fine! @@ -345,8 +346,8 @@ class WernisApi extends BaseFrameworkSystem { 'sub_request' => 'send', 't_uid' => $this->w_id, 't_md5' => $this->w_md5, - 'r_uid' => (int)$this->config['wernis_refid'], - 'amount' => (int)$amount, + 'r_uid' => (int) $this->config['wernis_refid'], + 'amount' => (int) $amount, 'purpose' => urlencode(base64_encode($purpose)) ); @@ -375,7 +376,7 @@ class WernisApi extends BaseFrameworkSystem { $url = $extract[0]; // Extract host name - $host = str_replace("http://", '', $url); + $host = str_replace('http://', '', $url); if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/')); // Generate relative URL @@ -390,8 +391,8 @@ class WernisApi extends BaseFrameworkSystem { } // Generate request header - $request = "GET /".trim($script)." HTTP/1.0\r\n"; - $request .= "Host: ".$host."\r\n"; + $request = "GET /" . trim($script) . " HTTP/1.0\r\n"; + $request .= "Host: " . $host . "\r\n"; $request .= sprintf("User-Agent: WernisApi/1.0 by Quix0r [Spieler: %d]\r\n\r\n", $this->w_id); // Initialize array