]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/stacker/class_BaseStacker.php
Continued:
[core.git] / framework / main / classes / stacker / class_BaseStacker.php
index be0a4c3adaea49ab5b01d991017575b6c5a8c76e..9e44c9b47b4ea82dcf28998db5529f0495a4c49a 100644 (file)
@@ -1,16 +1,20 @@
 <?php
 // Own namespace
-namespace CoreFramework\Stacker;
+namespace Org\Mxchange\CoreFramework\Stack;
 
 // Import framework stuff
-use CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+
+// Import SPL stuff
+use \BadMethodCallException;
 
 /**
  * A general Stacker
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -27,7 +31,7 @@ use CoreFramework\Object\BaseFrameworkSystem;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseStacker extends BaseFrameworkSystem {
+abstract class BaseStacker extends BaseFrameworkSystem {
        // Exception codes
        const EXCEPTION_STACKER_ALREADY_INITIALIZED = 0x050;
        const EXCEPTION_STACKER_IS_FULL             = 0x051;
@@ -40,7 +44,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
@@ -53,7 +57,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @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
@@ -69,7 +73,7 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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
@@ -83,7 +87,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @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'));
 
@@ -96,17 +100,17 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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?
-               $isFull = (($this->getStackCount($stackerName)) == $this->getConfigInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size'));
+               $isFull = (($this->getStackCount($stackerName)) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size'));
 
                // Return result
                return $isFull;
@@ -117,13 +121,13 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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?
@@ -138,13 +142,13 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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
@@ -162,7 +166,7 @@ class BaseStacker extends BaseFrameworkSystem {
         * @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
@@ -181,17 +185,17 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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
@@ -206,17 +210,17 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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
@@ -231,17 +235,17 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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
@@ -253,17 +257,17 @@ class BaseStacker extends BaseFrameworkSystem {
         *
         * @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