Introduced initStackers() which wraps initialization of several stacks
[core.git] / inc / classes / main / stacker / class_BaseStacker.php
index d28175804e3d47e511a0db7886156ae4c92919df..e329f60059a311da7eb1f31b00f7e0f46fe27681 100644 (file)
@@ -55,7 +55,20 @@ class BaseStacker extends BaseFrameworkSystem {
                } // END - if
 
                // Initialize the given stack
-               $this->initGenericArray('stacks', $stackerName, 'entries');
+               $this->initGenericArrayKey('stacks', $stackerName, 'entries', $forceReInit);
+       }
+
+       /**
+        * Initializes all stackers
+        *
+        * @return      void
+        */
+       public function initStackers (array $stacks) {
+               // "Walk" through all (more will be added as needed
+               foreach ($stacks as $stackerName) {
+                       // Init this stack
+                       $this->initStacker($stackerName);
+               } // END - foreach
        }
 
        /**
@@ -154,7 +167,7 @@ class BaseStacker extends BaseFrameworkSystem {
                }
 
                // Now add the value to the stack
-               $this->pushValueToGenericArrayElement('stacks', $stackerName, 'entries', $value);
+               $this->pushValueToGenericArrayKey('stacks', $stackerName, 'entries', $value);
        }
 
        /**
@@ -171,7 +184,7 @@ class BaseStacker extends BaseFrameworkSystem {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
@@ -196,12 +209,12 @@ class BaseStacker extends BaseFrameworkSystem {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now get the first value
-               $value = $this->popGenericArrayElement('stacks', $stackerName, 'entries', 0);
+               $value = $this->getGenericArrayElement('stacks', $stackerName, 'entries', 0);
 
                // Return it
                return $value;
@@ -211,7 +224,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * "Pops" last entry from stack
         *
         * @param       $stackerName    Name of the stack
-        * @return      void
+        * @return      $value                  Value "poped" from array
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
@@ -221,19 +234,19 @@ class BaseStacker extends BaseFrameworkSystem {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               $this->popGenericArrayElement('stacks', $stackerName, 'entries');
+               return $this->popGenericArrayElement('stacks', $stackerName, 'entries');
        }
 
        /**
         * "Pops" first entry from stack
         *
         * @param       $stackerName    Name of the stack
-        * @return      void
+        * @return      $value                  Value "shifted" from array
         * @throws      NoStackerException      If the named stacker was not found
         * @throws      EmptyStackerException   If the named stacker is empty
         */
@@ -243,12 +256,12 @@ class BaseStacker extends BaseFrameworkSystem {
                        // Throw an exception
                        throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
                } elseif ($this->isStackEmpty($stackerName)) {
-                       //Throw an exception
+                       // Throw an exception
                        throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
+               return $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
        }
 }