]> git.mxchange.org Git - core.git/commitdiff
Patches for making new generic array working
authorRoland Häder <roland@mxchange.org>
Sun, 23 Jun 2013 19:00:53 +0000 (19:00 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 23 Jun 2013 19:00:53 +0000 (19:00 +0000)
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/criteria/class_BaseCriteria.php
inc/classes/main/filter/class_FilterChain.php
inc/classes/main/registry/class_BaseRegistry.php
inc/classes/main/stacker/class_BaseStacker.php

index d146ed4b2202a64e491c1502a1ddfcf6caa00779..09d13a5786c2faae223e49a2559654226ae28587 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.');
                }
        }
 
@@ -2214,6 +2217,25 @@ 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
+        * @return      void
+        */
+       protected final function initGenericArray ($keyGroup, $subGroup, $key) {
+               // Is it already set?
+               if ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
+                       // Already initialized
+                       trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
+               } // END - if
+
+               // Initialize it
+               $this->genericArray[$keyGroup][$subGroup][$key] = array();
+       }
+
        /**
         * Pushes an element to a generic key
         *
@@ -2227,31 +2249,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=' . $value . 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 +2278,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) . ']=' . $value . PHP_EOL);
                return $value;
        }
 
@@ -2290,9 +2303,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 +2363,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 +2373,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 +2396,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 +2429,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
         *
index dfa0d4ee7879f7291884ee15b3f220b126df3a93..aa8a401b7afe9d7e2cc49b5cf5d6e2164030fe94 100644 (file)
@@ -303,7 +303,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria {
                } // END - foreach
 
                // Now check if expected criteria counts match
-               $matches = ($counted == $this->countGenericArrayGroup('criteria', $criteriaType)));
+               $matches = ($counted == $this->countGenericArrayGroup('criteria', $criteriaType));
 
                // Return the result
                return $matches;
@@ -416,7 +416,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         */
        public final function count ($criteriaType = 'default') {
                // Return it
-               return $this->countGenericArrayGroup('criteria', $criteriaType));
+               return $this->countGenericArrayGroup('criteria', $criteriaType);
        }
 
        /**
index ef173181f0acb042e645749d28bbf781224b153b..4f15fa13cd51334e349ecd8c2c52d4341936dc32 100644 (file)
@@ -61,7 +61,7 @@ class FilterChain extends BaseFrameworkSystem implements Registerable {
         * @return      $filters        The filters array holding all filter instances
         */
        protected function getFilters () {
-               return $this->getGenericArray('filters');
+               return $this->getGenericArrayKey('filters', 'generic', 'dummy');
        }
 
        /**
@@ -75,6 +75,9 @@ class FilterChain extends BaseFrameworkSystem implements Registerable {
                // Run all filters
                //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('COUNT=' . $this->countGenericArray('filters'));
                foreach ($this->getFilters() as $filterInstance) {
+                       // Must be an instance of Filterable
+                       assert($filterInstance instanceof Filterable);
+
                        // Try to execute this filter
                        try {
                                //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('FILTER: ' . $filterInstance->__toString() . ': Processing started.');
index df0f9798fdf75a2d070da93182b4dc016397356b..f39457cf07f4f5b32085ececa9abbfc45dedccd5 100644 (file)
@@ -65,7 +65,7 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public function addInstance ($instanceKey, Registerable $objectInstance) {
-               $this->pushValueToGenericArrayElement('registry', 'instance', $instanceKey, $objectInstance);
+               $this->setGenericArrayKey('registry', 'instance', $instanceKey, $objectInstance);
        }
 
        /**
@@ -86,6 +86,9 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable {
         * @return      void
         */
        public final function addEntry ($key, $value) {
+               // Key must not be an array
+               assert(!is_array($key));
+
                // Push it
                $this->pushValueToGenericArrayElement('raw', 'generic', $key, $value);
        }
@@ -96,6 +99,9 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable {
         * @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));
+
                // Default is whole array
                $entries = $this->getGenericArray('raw');
 
@@ -117,6 +123,9 @@ class BaseRegistry extends BaseFrameworkSystem implements Registerable {
         * @return      $entry          An array with all keys
         */
        public function getArrayFromKey ($arrayKey, $lookFor) {
+               // Key must not be an array
+               assert(!is_array($arrayKey));
+
                // Init array
                $entry = array();
 
index 40f7c0514d8e03867bde9debca0199a95441f7be..bf4a7667f3856a43f1a0bc2fe02a00b9a167a00d 100644 (file)
@@ -55,7 +55,7 @@ class BaseStacker extends BaseFrameworkSystem {
                } // END - if
 
                // Initialize the given stack
-               $this->pushValueToGenericArrayElement('stacks', $stackerName, 'max_size', $this->getConfigInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size'));
+               $this->initGenericArray('stacks', $stackerName, 'entries');
        }
 
        /**
@@ -176,7 +176,7 @@ class BaseStacker extends BaseFrameworkSystem {
                }
 
                // Now get the last value
-               $value = $this->getGenericArrayKey('stacks', $stackerName, 'entries', $this->getStackCount($stackerName) - 1);
+               $value = $this->getGenericArrayElement('stacks', $stackerName, 'entries', $this->getStackCount($stackerName) - 1);
 
                // Return it
                return $value;