From 7dd76b61aa39deab983fecadef400ee9e8c95ebc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 23 Apr 2010 23:01:25 +0000 Subject: [PATCH] FIFO basicly finished --- .../main/stacker/class_BaseStacker.php | 47 +++++++++++++++++++ .../main/stacker/fifo/class_FiFoStacker.php | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/inc/classes/main/stacker/class_BaseStacker.php b/inc/classes/main/stacker/class_BaseStacker.php index 5c25e928..2fdc0d25 100644 --- a/inc/classes/main/stacker/class_BaseStacker.php +++ b/inc/classes/main/stacker/class_BaseStacker.php @@ -189,6 +189,31 @@ class BaseStacker extends BaseFrameworkSystem { return $value; } + /** + * Get first value from named stacker + * + * @param $stackerName Name of the stack + * @return $value Value of last added value + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected final function getFirstValue ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + //Throw an exception + throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + } + + // Now get the last value + $value = $this->stacks[$stackerName]['entries'][0]; + + // Return it + return $value; + } + /** * "Pops" last entry from stack * @@ -210,6 +235,28 @@ class BaseStacker extends BaseFrameworkSystem { // Now, remove the last entry, we don't care about the return value here, see elseif() block above array_pop($this->stacks[$stackerName]['entries']); } + + /** + * "Pops" first entry from stack + * + * @param $stackerName Name of the stack + * @return void + * @throws NoStackerException If the named stacker was not found + * @throws EmptyStackerException If the named stacker is empty + */ + protected final function popFirst ($stackerName) { + // Is the stack not yet initialized or full? + if (!$this->isStackInitialized($stackerName)) { + // Throw an exception + throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND); + } elseif ($this->isStackEmpty($stackerName)) { + //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 + array_shift($this->stacks[$stackerName]['entries']); + } } // [EOF] diff --git a/inc/classes/main/stacker/fifo/class_FiFoStacker.php b/inc/classes/main/stacker/fifo/class_FiFoStacker.php index c2cc09eb..f8fe041b 100644 --- a/inc/classes/main/stacker/fifo/class_FiFoStacker.php +++ b/inc/classes/main/stacker/fifo/class_FiFoStacker.php @@ -84,7 +84,7 @@ class FiFoStacker extends BaseStacker implements Stackable { */ public function getNamed ($stackerName) { // Call the protected method - return parent::getLastValue($stackerName); + return parent::getFirstValue($stackerName); } } -- 2.30.2