Fixes and double->single converted
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index d42cfc3968cf0c06554df81e1d23c10c3dbb2015..d146ed4b2202a64e491c1502a1ddfcf6caa00779 100644 (file)
@@ -163,6 +163,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $visitorInstance = NULL;
 
+       /**
+        * DHT instance
+        */
+       private $dhtInstance = NULL;
+
        /**
         * An instance of a database wrapper class
         */
@@ -181,13 +186,18 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        /**
         * Socket resource
         */
-       private $socketResource = false;
+       private $socketResource = FALSE;
 
        /**
         * Package data
         */
        private $packageData = array();
 
+       /**
+        * Generic array
+        */
+       private $genericArray = array();
+
        /***********************
         * Exception codes.... *
         ***********************/
@@ -328,7 +338,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      void
         */
-       public function __destruct() {
+       public function __destruct () {
                // Flush any updated entries to the database
                $this->flushPendingUpdates();
 
@@ -338,7 +348,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        $this->setRealClass('DestructedObject');
                } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
                        // Already destructed object
-                       $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
+                       self::createDebugInstance(__CLASS__)->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
                                __CLASS__,
                                $this->__toString()
                        ));
@@ -353,8 +363,21 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function __call ($methodName, $args) {
-               // Implode all given arguments
+               return self::__callStatic($methodName, $args);
+       }
+
+       /**
+        * The __callStatic() method where all non-implemented static methods end up
+        *
+        * @param       $methodName             Name of the missing method
+        * @args        $args                   Arguments passed to the method
+        * @return      void
+        */
+       public static final function __callStatic ($methodName, $args) {
+               // Init argument string
                $argsString = '';
+
+               // Is it empty or an array?
                if (empty($args)) {
                        // No arguments
                        $argsString = 'NULL';
@@ -373,14 +396,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 
                                if (is_string($arg)) {
                                        // Add length for strings
-                                       $argsString .= ', '.strlen($arg);
+                                       $argsString .= ', ' . strlen($arg);
                                } elseif (is_array($arg)) {
                                        // .. or size if array
-                                       $argsString .= ', '.count($arg);
-                               } elseif ($arg === true) {
+                                       $argsString .= ', ' . count($arg);
+                               } elseif ($arg === TRUE) {
                                        // ... is boolean 'true'
                                        $argsString .= ', true';
-                               } elseif ($arg === false) {
+                               } elseif ($arg === FALSE) {
                                        // ... is boolean 'true'
                                        $argsString .= ', false';
                                }
@@ -399,8 +422,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                }
 
                // Output stub message
-               $this->debugOutput(sprintf("[%s-&gt;%s] Stub! Args: %s",
-                       $this->__toString(),
+               // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
+               self::createDebugInstance(__CLASS__)->debugOutput(sprintf("[unknown::%s:] Stub! Args: %s",
                        $methodName,
                        $argsString
                ));
@@ -765,7 +788,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param       $fileIoInstance         An instance to the file I/O sub-system
         * @return      void
         */
-       public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
+       public final function setFileIoInstance (IoHandler $fileIoInstance) {
                $this->fileIoInstance = $fileIoInstance;
        }
 
@@ -979,19 +1002,19 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Setter for BaseDatabaseWrapper instance
+        * Setter for DatabaseWrapper instance
         *
-        * @param       $wrapperInstance        An instance of an BaseDatabaseWrapper
+        * @param       $wrapperInstance        An instance of an DatabaseWrapper
         * @return      void
         */
-       public final function setWrapperInstance (BaseDatabaseWrapper $wrapperInstance) {
+       public final function setWrapperInstance (DatabaseWrapper $wrapperInstance) {
                $this->wrapperInstance = $wrapperInstance;
        }
 
        /**
-        * Getter for BaseDatabaseWrapper instance
+        * Getter for DatabaseWrapper instance
         *
-        * @return      $wrapperInstance        An instance of an BaseDatabaseWrapper
+        * @return      $wrapperInstance        An instance of an DatabaseWrapper
         */
        public final function getWrapperInstance () {
                return $this->wrapperInstance;
@@ -1004,6 +1027,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function setSocketResource ($socketResource) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
                $this->socketResource = $socketResource;
        }
 
@@ -1012,7 +1036,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      $socketResource         A valid socket resource
         */
-       public function getSocketResource () {
+       public final function getSocketResource () {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
                return $this->socketResource;
        }
 
@@ -1130,6 +1155,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->visitorInstance;
        }
 
+       /**
+        * Setter for DHT instance
+        *
+        * @param       $dhtInstance    A Distributable instance
+        * @return      void
+        */
+       protected final function setDhtInstance (Distributable $dhtInstance) {
+               $this->dhtInstance = $dhtInstance;
+       }
+
+       /**
+        * Getter for DHT instance
+        *
+        * @return      $dhtInstance    A Distributable instance
+        */
+       protected final function getDhtInstance () {
+               return $this->dhtInstance;
+       }
+
        /**
         * Setter for raw package Data
         *
@@ -1303,7 +1347,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                );
 
                // Output it
-               ApplicationEntryPoint::app_die(sprintf("<div class=\"debug_header\">%s debug output:</div><div class=\"debug_content\">%s</div>\nLoaded includes: <div class=\"debug_include_list\">%s</div>",
+               ApplicationEntryPoint::app_exit(sprintf("<div class=\"debug_header\">%s debug output:</div><div class=\"debug_content\">%s</div>\nLoaded includes: <div class=\"debug_include_list\">%s</div>",
                        $this->__toString(),
                        $content,
                        ClassLoader::getSelfInstance()->getPrintableIncludeList()
@@ -1353,16 +1397,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Is the extra message given?
                if (!empty($message)) {
                        // Then add it as well
-                       $stubMessage .= sprintf(' Message: <span id="stub_message">%s</span>', $message);
+                       $stubMessage .= ' Message: ' . $message;
                } // END - if
 
                // Debug instance is there?
                if (!is_null($this->getDebugInstance())) {
                        // Output stub message
-                       $this->debugOutput($stubMessage);
+                       self::createDebugInstance(__CLASS__)->debugOutput($stubMessage);
                } else {
                        // Trigger an error
-                       trigger_error($stubMessage . '<br />' . chr(10));
+                       trigger_error($stubMessage);
                }
        }
 
@@ -1373,7 +1417,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param       $doExit         Whether exit the program (true is default)
         * @return      void
         */
-       public function debugBackTrace ($message = '', $doExit = true) {
+       public function debugBackTrace ($message = '', $doExit = TRUE) {
                // Sorry, there is no other way getting this nice backtrace
                if (!empty($message)) {
                        // Output message
@@ -1385,48 +1429,82 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                print('</pre>');
 
                // Exit program?
-               if ($doExit === true) {
+               if ($doExit === TRUE) {
                        exit();
                } // END - if
        }
 
        /**
-        * Outputs a debug message whether to debug instance (should be set!) or dies with or pints the message
+        * Creates an instance of a debugger instance
+        *
+        * @param       $className              Name of the class (currently unsupported)
+        * @return      $debugInstance  An instance of a debugger class
+        */
+       public final static function createDebugInstance ($className) {
+               // Init debug instance
+               $debugInstance = NULL;
+
+               // Try it
+               try {
+                       // Get a debugger instance
+                       $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
+               } catch (NullPointerException $e) {
+                       // Didn't work, no instance there
+                       exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
+               }
+
+               // Empty string should be ignored and used for testing the middleware
+               DebugMiddleware::getSelfInstance()->output('');
+
+               // Return it
+               return $debugInstance;
+       }
+
+       /**
+        * Outputs a debug message whether to debug instance (should be set!) or
+        * dies with or ptints the message. Do NEVER EVER rewrite the exit() call to
+        * ApplicationEntryPoint::app_exit(), this would cause an endless loop.
         *
         * @param       $message        Message we shall send out...
-        * @param       $doPrint        Whether we shall print or die here which first is the default
+        * @param       $doPrint        Whether print or die here (default: print)
+        * @paran       $stripTags      Whether to strip tags (default: false)
         * @return      void
         */
-       public function debugOutput ($message, $doPrint = true) {
-               // Get debug instance
-               $debugInstance = $this->getDebugInstance();
+       public function debugOutput ($message, $doPrint = TRUE, $stripTags = FALSE) {
+               // Set debug instance to NULL
+               $debugInstance = NULL;
+
+               // Try it:
+               try {
+                       // Get debug instance
+                       $debugInstance = $this->getDebugInstance();
+               } catch (NullPointerException $e) {
+                       // The debug instance is not set (yet)
+               }
 
                // Is the debug instance there?
                if (is_object($debugInstance)) {
                        // Use debug output handler
-                       $debugInstance->output($message);
+                       $debugInstance->output($message, $stripTags);
 
-                       if ($doPrint === false) {
+                       if ($doPrint === FALSE) {
                                // Die here if not printed
-                               die();
+                               exit();
                        } // END - if
                } else {
-                       // Put directly out
-                       if ($doPrint === true) {
-                               // Are debug times enabled?
-                               if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
-                                       // Output it first
-                                       print($this->getPrintableExecutionTime());
-                               } // END - if
+                       // Are debug times enabled?
+                       if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
+                               // Prepent it
+                               $message = $this->getPrintableExecutionTime() . $message;
+                       } // END - if
 
+                       // Put directly out
+                       if ($doPrint === TRUE) {
                                // Print message
                                print($message . chr(10));
                        } else {
-                               /*
-                                * BIG FAT NOTE: Do NEVER rewrite this to app_die(), this will
-                                * cause an endless loop.
-                                */
-                               die($message);
+                               // Die here
+                               exit($message);
                        }
                }
        }
@@ -1590,7 +1668,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                $this->getResultInstance()->rewind();
 
                // Do we have an entry?
-               if ($this->getResultInstance()->valid() === false) {
+               if ($this->getResultInstance()->valid() === FALSE) {
                        throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
                } // END - if
 
@@ -1626,7 +1704,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 
                // Get current array
                $fieldArray = $resultInstance->current();
-               //* DEBUG: */ $this->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
+
+               // Convert dashes to underscore
+               $fieldName = $this->convertDashesToUnderscores($fieldName);
 
                // Does the field exist?
                if (isset($fieldArray[$fieldName])) {
@@ -1634,7 +1715,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        $fieldValue = $fieldArray[$fieldName];
                } else {
                        // Missing field entry, may require debugging
-                       $this->debugOutput($this->__toString() . ':fieldname=' . $fieldName . ' not found!');
+                       self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ':fieldname=' . $fieldName . ' not found!');
                }
 
                // Return it
@@ -1676,7 +1757,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        // Debug instance is there?
                        if (!is_null($this->getDebugInstance())) {
                                // Output stub message
-                               $this->debugOutput($message);
+                               self::createDebugInstance(__CLASS__)->debugOutput($message);
                        } else {
                                // Trigger an error
                                trigger_error($message . "<br />\n");
@@ -1722,7 +1803,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        public function idle ($milliSeconds) {
                // Sleep is fine by default
-               $hasSlept = true;
+               $hasSlept = TRUE;
 
                // Idle so long with found function
                if (function_exists('time_sleep_until')) {
@@ -1775,8 +1856,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Converts even very large decimal numbers, also with negative sign, to a
-        * hexadecimal string.
+        * Converts even very large decimal numbers, also signed, to a hexadecimal
+        * string.
         *
         * This work is based on comment #97756 on php.net documentation page at:
         * <http://de.php.net/manual/en/function.hexdec.php#97756>
@@ -1799,18 +1880,20 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Encode the decimal number into a hexadecimal string
                $hex = '';
                do {
-                       $hex = self::$dechex[($dec % 16)] . $hex;
-                       $dec /= 16;
+                       $hex = self::$dechex[($dec % (2 ^ 4))] . $hex;
+                       $dec /= (2 ^ 4);
                } while ($dec >= 1);
 
                /*
-                * We need hexadecimal strings with leading zeros if the length cannot
-                * be divided by 2
+                * Leading zeros are required for hex-decimal "numbers". In some
+                * situations more leading zeros are wanted, so check for both
+                * conditions.
                 */
                if ($maxLength > 0) {
                        // Prepend more zeros
-                       $hex = $this->prependStringToString($hex, '0', $maxLength);
+                       $hex = str_pad($hex, $maxLength, '0', STR_PAD_LEFT);
                } elseif ((strlen($hex) % 2) != 0) {
+                       // Only make string's length dividable by 2
                        $hex = '0' . $hex;
                }
 
@@ -1861,7 +1944,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        protected function hex2asc ($hex) {
                // Check for length, it must be devideable by 2
-               //* DEBUG: */ $this->debugOutput('hex='.$hex);
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('hex='.$hex);
                assert((strlen($hex) % 2) == 0);
 
                // Walk the string
@@ -1878,41 +1961,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $asc;
        }
 
-       /**
-        * Prepends a given string $prepend to $str with a given total length
-        *
-        * @param       $str            Given original string which should be prepended
-        * @param       $prepend        The string to prepend
-        * @param       $length         Total length of the final string
-        * @return      $strFinal       Final prepended string
-        */
-       protected function prependStringToString ($str, $prepend, $length) {
-               // Set final string to original string by default
-               $strFinal = $str;
-
-               // Can it devided
-               if (strlen($str) < $length) {
-                       // Difference between total length and length of original string
-                       $diff = $length - strlen($str);
-
-                       // Prepend the string
-                       $prepend = str_repeat($prepend, ($diff / strlen($prepend) + 1));
-
-                       // Make sure it will definedly fit
-                       assert(strlen($prepend) >= $diff);
-
-                       // Cut it a little down
-                       $prepend = substr($prepend, 0, $diff);
-                       //* DEBUG: */ $this->debugOutput('prepend('.strlen($prepend).')='.$prepend.',diff='.$diff.',length='.$length);
-
-                       // Construct the final prepended string
-                       $strFinal = $prepend . $str;
-               } // END - if
-
-               // Return it
-               return $strFinal;
-       }
-
        /**
         * Checks whether the given encoded data was encoded with Base64
         *
@@ -1921,7 +1969,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        protected function isBase64Encoded ($encodedData) {
                // Determine it
-               $isBase64 = (@base64_decode($encodedData, true) !== false);
+               $isBase64 = (@base64_decode($encodedData, true) !== FALSE);
 
                // Return it
                return $isBase64;
@@ -1961,7 +2009,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                );
 
                // And return it
-               //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
                return $cacheKey;
        }
 
@@ -2012,18 +2060,18 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param       $assertMismatch         Whether to assert mismatches
         * @return      $ret            The (hopefully) secured numbered value
         */
-       public function bigintval ($num, $castValue = true, $assertMismatch = false) {
+       public function bigintval ($num, $castValue = TRUE, $assertMismatch = FALSE) {
                // Filter all numbers out
                $ret = preg_replace('/[^0123456789]/', '', $num);
 
                // Shall we cast?
-               if ($castValue === true) {
+               if ($castValue === TRUE) {
                        // Cast to biggest numeric type
                        $ret = (double) $ret;
                } // END - if
 
                // Assert only if requested
-               if ($assertMismatch === true) {
+               if ($assertMismatch === TRUE) {
                        // Has the whole value changed?
                        assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
                } // END - if
@@ -2031,6 +2079,359 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return result
                return $ret;
        }
+
+       /**
+        * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
+        *
+        * @param       $num    A string consisting only chars between 0 and 9
+        * @param       $assertMismatch         Whether to assert mismatches
+        * @return      $ret    The (hopefully) secured hext-numbered value
+        */
+       public function hexval ($num, $assertMismatch = FALSE) {
+               // Filter all numbers out
+               $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
+
+               // Assert only if requested
+               if ($assertMismatch === TRUE) {
+                       // Has the whole value changed?
+                       assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
+               } // END - if
+
+               // Return result
+               return $ret;
+       }
+
+       /**
+        * Checks whether start/end marker are set
+        *
+        * @param       $data   Data to be checked
+        * @return      $isset  Whether start/end marker are set
+        */
+       public final function ifStartEndMarkersSet ($data) {
+               // Determine it
+               $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+               // ... 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]