X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fstacker%2Fclass_BaseStacker.php;h=2fdc0d2556dd62494b3902bc066e053f5b2861d4;hp=4225cb731b57e7ee7c895ae056c70613a8111441;hb=51caaa61ae7ee017abdfd116bbd8c438451315b2;hpb=84e2207412d3c6ea9f940a83b2cdd4503509808a diff --git a/inc/classes/main/stacker/class_BaseStacker.php b/inc/classes/main/stacker/class_BaseStacker.php index 4225cb73..2fdc0d25 100644 --- a/inc/classes/main/stacker/class_BaseStacker.php +++ b/inc/classes/main/stacker/class_BaseStacker.php @@ -71,7 +71,7 @@ class BaseStacker extends BaseFrameworkSystem { * @param $stackerName Name of the stack * @return $isInitialized Wether the stack is initialized */ - protected final function isStackInitialized ($stackerName) { + public final function isStackInitialized ($stackerName) { // Is is there? $isInitialized = ((isset($this->stacks[$stackerName])) && (is_array($this->stacks[$stackerName]))); @@ -86,7 +86,7 @@ class BaseStacker extends BaseFrameworkSystem { * @return $isFull Wether the stack is full * @throws NoStackerException If given stack is missing */ - protected final function isStackFull($stackerName) { + protected final function isStackFull ($stackerName) { // Is the stack not yet initialized? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -107,7 +107,7 @@ class BaseStacker extends BaseFrameworkSystem { * @return $isEmpty Wether the stack is empty * @throws NoStackerException If given stack is missing */ - protected final function isStackEmpty($stackerName) { + public final function isStackEmpty ($stackerName) { // Is the stack not yet initialized? if (!$this->isStackInitialized($stackerName)) { // Throw an exception @@ -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]