Added option parameter 'forceInit'
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index d146ed4b2202a64e491c1502a1ddfcf6caa00779..0fb474dcb865fafa32ceb60749b6428817b2439b 100644 (file)
@@ -348,10 +348,13 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        $this->setRealClass('DestructedObject');
                } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
                        // Already destructed object
-                       self::createDebugInstance(__CLASS__)->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()
                        ));
+               } else {
+                       // Do not call this twice
+                       trigger_error(__METHOD__ . ': Called twice.');
                }
        }
 
@@ -2116,38 +2119,38 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Determines if a key is set in the generic array
+        * 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 isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
+       protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
                // Is it there?
-               $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
+               $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
 
                // Return it
                return $isset;
        }
-
        /**
-        * Determines if an element is set in the generic array
+        * 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
-        * @param       $element        Element to check
         * @return      $isset          Whether the given key is set
         */
-       protected final function isGenericArrayElementSet ($keyGroup, $subGroup, $key, $element) {
+       protected final function isGenericArrayKeySet ($keyGroup, $subGroup, $key) {
                // Is it there?
-               $isset = isset($this->genericArray[$keyGroup][$subGroup][$key][$element]);
+               $isset = isset($this->genericArray[$keyGroup][$subGroup][$key]);
 
                // Return it
                return $isset;
        }
 
+
        /**
         * Determines if a group is set in the generic array
         *
@@ -2178,6 +2181,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } // END - if
 
                // Return it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' returning!' . PHP_EOL);
                return $this->genericArray[$keyGroup][$subGroup];
        }
 
@@ -2191,6 +2195,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        protected final function unsetGenericArrayElement ($keyGroup, $subGroup, $key) {
                // Remove it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' unset!' . PHP_EOL);
                unset($this->genericArray[$keyGroup][$subGroup][$key]);
        }
 
@@ -2214,6 +2219,27 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                }
        }
 
+       /**
+        * Initializes given generic array
+        *
+        * @param       $keyGroup       Main group for the key
+        * @param       $subGroup       Sub group for the key
+        * @param       $key            Key to use
+        * @param       $forceInit      Optionally force initialization
+        * @return      void
+        */
+       protected final function initGenericArray ($keyGroup, $subGroup, $key, $forceInit = FALSE) {
+               // Is it already set?
+               if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
+                       // Already initialized
+                       trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
+               } // END - if
+
+               // Initialize it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . PHP_EOL);
+               $this->genericArray[$keyGroup][$subGroup][$key] = array();
+       }
+
        /**
         * Pushes an element to a generic key
         *
@@ -2227,31 +2253,19 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Is it set?
                if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Initialize array
-                       $this->genericArray[$keyGroup][$subGroup][$key] = array();
+                       $this->initGenericArray($keyGroup, $subGroup, $key);
                } // END - if
 
                // Then push it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
                $count = array_push($this->genericArray[$keyGroup][$subGroup][$key], $value);
 
                // Return count
+               //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
+               //* DEBUG: */ print(__METHOD__ . ': count=' . $count . PHP_EOL);
                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
         *
@@ -2268,9 +2282,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } // END - if
 
                // Then "pop" it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' pop-ing entry ...' . PHP_EOL);
                $value = array_pop($this->genericArray[$keyGroup][$subGroup][$key]);
 
                // Return value
+               //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
+               //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . print_r($value, TRUE) . PHP_EOL);
                return $value;
        }
 
@@ -2290,9 +2307,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } // END - if
 
                // Then "shift" it
+               //* DEBUG: */ print(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' shifting entry ...' . PHP_EOL);
                $value = array_shift($this->genericArray[$keyGroup][$subGroup][$key]);
 
                // Return value
+               //* DEBUG: */ print(__METHOD__ . ': genericArray=' . print_r($this->genericArray[$keyGroup][$subGroup][$key], TRUE));
+               //* DEBUG: */ print(__METHOD__ . ': value[' . gettype($value) . ']=' . $value . PHP_EOL);
                return $value;
        }
 
@@ -2347,7 +2367,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        protected final function countGenericArrayElements ($keyGroup, $subGroup, $key) {
                // Is it there?
-               if (!$this->isGenericArrayKeySet($keyGroup, $subGroup)) {
+               if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
                } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
@@ -2357,6 +2377,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 
                // Then count it
                $count = count($this->genericArray[$keyGroup][$subGroup][$key]);
+               //* DEBUG: */ print(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',count=' . $count . PHP_EOL);
 
                // Return it
                return $count;
@@ -2379,6 +2400,20 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->genericArray[$keyGroup];
        }
 
+       /**
+        * Setter for generic array key
+        *
+        * @param       $keyGroup       Key group to get
+        * @param       $subGroup       Sub group for the key
+        * @param       $key            Key to unset
+        * @param       $value          Mixed value from generic array element
+        * @return      void
+        */
+       protected final function setGenericArrayKey ($keyGroup, $subGroup, $key, $value) {
+               // Set value here
+               $this->genericArray[$keyGroup][$subGroup][$key] = $value;
+       }
+
        /**
         * Getter for generic array key
         *
@@ -2398,6 +2433,21 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->genericArray[$keyGroup][$subGroup][$key];
        }
 
+       /**
+        * 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;
+       }
+
        /**
         * Getter for generic array element
         *
@@ -2432,6 +2482,22 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return it
                return $isValid;
        }
+
+       /**
+        * Checks if a given key is valid (array)
+        *
+        * @param       $keyGroup       Key group to get
+        * @param       $subGroup       Sub group for the key
+        * @param       $key            Key to check
+        * @return      $isValid        Whether given sub group is valid
+        */
+       protected final function isValidGenericArrayKey ($keyGroup, $subGroup, $key) {
+               // Determine it
+               $isValid = (($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) && (is_array($this->getGenericArrayKey($keyGroup, $subGroup, $key))));
+
+               // Return it
+               return $isValid;
+       }
 }
 
 // [EOF]