Renamed 'stacker' -> 'stack'
[core.git] / inc / classes / main / stacker / class_BaseStacker.php
index 7b4c18cd434189d774e79775a0b28ecf083b9359..12cfc03113c0163ad1b7775b9e40c5414ca80145 100644 (file)
@@ -47,15 +47,28 @@ class BaseStacker extends BaseFrameworkSystem {
         * @return      void
         * @throws      AlreadyInitializedStackerException      If the stack is already initialized
         */
-       public final function initStacker ($stackerName, $forceReInit = FALSE) {
+       public final function initStack ($stackerName, $forceReInit = FALSE) {
                // Is the stack already initialized?
                if (($forceReInit === FALSE) && ($this->isStackInitialized($stackerName))) {
                        // Then throw the exception
-                       throw new AlreadyInitializedStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_ALREADY_INITIALIZED);
+                       throw new AlreadyInitializedStackerException(array($this, $stackerName, $forceReInit), self::EXCEPTION_STACKER_ALREADY_INITIALIZED);
                } // END - if
 
                // Initialize the given stack
-               $this->initGenericArray('stacks', $stackerName, 'entries');
+               $this->initGenericArrayKey('stacks', $stackerName, 'entries', $forceReInit);
+       }
+
+       /**
+        * Initializes all stacks
+        *
+        * @return      void
+        */
+       public function initStacks (array $stacks, $forceReInit = FALSE) {
+               // "Walk" through all (more will be added as needed
+               foreach ($stacks as $stackerName) {
+                       // Init this stack
+                       $this->initStack($stackerName, $forceReInit);
+               } // END - foreach
        }
 
        /**
@@ -66,7 +79,7 @@ class BaseStacker extends BaseFrameworkSystem {
         */
        public final function isStackInitialized ($stackerName) {
                // Is is there?
-               $isInitialized = ($this->isValidGenericArrayGroup('stacks', $stackerName));
+               $isInitialized = ($this->isValidGenericArrayKey('stacks', $stackerName, 'entries'));
 
                // Return result
                return $isInitialized;
@@ -147,14 +160,14 @@ class BaseStacker extends BaseFrameworkSystem {
                // Is the stack not yet initialized or full?
                if (!$this->isStackInitialized($stackerName)) {
                        // Then do it here
-                       $this->initStacker($stackerName);
+                       $this->initStack($stackerName);
                } elseif ($this->isStackFull($stackerName)) {
                        // Stacker is full
                        throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL);
                }
 
                // 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');
        }
 }