<?php
// Own namespace
-namespace Org\Mxchange\CoreFramework\Stacker;
+namespace Org\Mxchange\CoreFramework\Stack;
// Import framework stuff
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \BadMethodCallException;
+
/**
* A general Stacker
*
* @return void
* @throws AlreadyInitializedStackerException If the stack is already initialized
*/
- public function initStack ($stackerName, $forceReInit = false) {
+ public function initStack (string $stackerName, bool $forceReInit = false) {
// Is the stack already initialized?
if (($forceReInit === false) && ($this->isStackInitialized($stackerName))) {
// Then throw the exception
*
* @return void
*/
- public function initStacks (array $stacks, $forceReInit = false) {
+ public function initStacks (array $stacks, bool $forceReInit = false) {
// "Walk" through all (more will be added as needed
foreach ($stacks as $stackerName) {
// Init this stack
* @param $stackerName Name of the stack
* @return $isInitialized Whether the stack is initialized
*/
- public function isStackInitialized ($stackerName) {
+ public function isStackInitialized (string $stackerName) {
// Is is there?
$isInitialized = ($this->isValidGenericArrayKey('stacks', $stackerName, 'entries'));
*
* @param $stackerName Name of the stack
* @return $isFull Whether the stack is full
- * @throws NoStackerException If given stack is missing
+ * @throws BadMethodCallException If given stack is missing
*/
- protected function isStackFull ($stackerName) {
+ protected function isStackFull (string $stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
- throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} // END - if
// So, is the stack full?
*
* @param $stackerName Name of the stack
* @return $isEmpty Whether the stack is empty
- * @throws NoStackerException If given stack is missing
+ * @throws BadMethodCallException If given stack is missing
*/
- public function isStackEmpty ($stackerName) {
+ public function isStackEmpty (string $stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
- throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} // END - if
// So, is the stack empty?
*
* @param $stackerName Name of the stack
* @return $count Size of stack (array count)
- * @throws NoStackerException If given stack is missing
+ * @throws BadMethodCallException If given stack is missing
*/
- public function getStackCount ($stackerName) {
+ public function getStackCount (string $stackerName) {
// Is the stack not yet initialized?
if (!$this->isStackInitialized($stackerName)) {
// Throw an exception
- throw new NoStackerException(array($this, $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} // END - if
// Now, count the array of entries
* @return void
* @throws FullStackerException Thrown if the stack is full
*/
- protected function addValue ($stackerName, $value) {
+ protected function addValue (string $stackerName, $value) {
// Is the stack not yet initialized or full?
if (!$this->isStackInitialized($stackerName)) {
// Then do it here
*
* @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
+ * @throws BadMethodCallException If the named stacker was not found
+ * @throws BadMethodCallException If the named stacker is empty
*/
- protected function getLastValue ($stackerName) {
+ protected function getLastValue (string $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);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
}
// Now get the last value
*
* @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
+ * @throws BadMethodCallException If the named stacker was not found
+ * @throws BadMethodCallException If the named stacker is empty
*/
- protected function getFirstValue ($stackerName) {
+ protected function getFirstValue (string $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);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
}
// Now get the first value
*
* @param $stackerName Name of the stack
* @return $value Value "poped" from array
- * @throws NoStackerException If the named stacker was not found
- * @throws EmptyStackerException If the named stacker is empty
+ * @throws BadMethodCallException If the named stacker was not found
+ * @throws BadMethodCallException If the named stacker is empty
*/
- protected function popLast ($stackerName) {
+ protected function popLast (string $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);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
}
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
*
* @param $stackerName Name of the stack
* @return $value Value "shifted" from array
- * @throws NoStackerException If the named stacker was not found
- * @throws EmptyStackerException If the named stacker is empty
+ * @throws BadMethodCallException If the named stacker was not found
+ * @throws BadMethodCallException If the named stacker is empty
*/
- protected function popFirst ($stackerName) {
+ protected function popFirst (string $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);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
}
// Now, remove the last entry, we don't care about the return value here, see elseif() block above