]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php
Continued:
[core.git] / framework / main / classes / stacker / file / fifo / class_FiFoFileStack.php
index 5db1e2af0068fe64855161f58e1497d30b0cca02..4fec83552a73c296c5ac1b94f1fbc6121f852fbf 100644 (file)
@@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Stack\File\BaseFileStack;
 use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileInfo;
 
 /**
@@ -50,15 +51,25 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         * @param       $fileInfoInstance       An instance of a SplFileInfo class
         * @param       $type                   Type of this stack (e.g. url_source for URL sources)
         * @return      $stackInstance  An instance of a StackableFile class
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, $type) {
+       public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, string $type) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: fileInfoInstance[%s]=%s,type=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $type));
+               if (empty($type)) {
+                       // No empty type
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               }
+
                // Get new instance
                $stackInstance = new FiFoFileStack();
 
                // Init this stack
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Calling stackInstance->initFileStack([%s]=%s,%s) ...', get_class($fileInfoInstance), $fileInfoInstance, $type));
                $stackInstance->initFileStack($fileInfoInstance, $type);
 
                // Return the prepared instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackInstance=%s - EXIT!', $stackInstance->__toString()));
                return $stackInstance;
        }
 
@@ -68,11 +79,26 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         * @param       $stackerName    Name of the stack
         * @param       $value                  Value to push on it
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      StackerFullException    If the stack is full
         */
        public function pushNamed (string $stackerName, $value) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               } elseif (is_object($value) || is_resource($value)) {
+                       // Those types for $value are not allowed
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not valid', gettype($value)));
+               }
+
                // Call the protected method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
                parent::addValue($stackerName, $value);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: EXIT!');
        }
 
        /**
@@ -80,17 +106,27 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of the current stack entry
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      BadMethodCallException  If the named stacker was not found
         * @throws      BadMethodCallException  If the named stacker is empty
         */
        public function popNamed (string $stackerName) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               }
+
                // Get the value
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: this->getNamed(%s) ...', $stackerName));
                $value = $this->getNamed($stackerName);
 
                // Call the protected method
                parent::popFirst($stackerName);
 
                // Return the value
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
                return $value;
        }
 
@@ -99,12 +135,25 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of last added value
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      BadMethodCallException  If the named stacker was not found
         * @throws      BadMethodCallException  If the named stacker is empty
         */
        public function getNamed (string $stackerName) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               }
+
                // Call the protected method
-               return parent::getFirstValue($stackerName);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: parent::getFirstValue(%s) ...', $stackerName));
+               $value = parent::getFirstValue($stackerName);
+
+               // Return the value
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
+               return $value;
        }
 
        /**
@@ -112,9 +161,21 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         *
         * @param       $seekPosition   Seek position in file
         * @return      $status                 Status of this operation
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public function seek ($seekPosition) {
+       public function seek (int $seekPosition) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d - CALLED!', $seekPosition));
+               if ($seekPosition < 0) {
+                       // Invalid seek position
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+               }
+
+               // @TODO Unfinished method or invoke inner iterator's method?
                $this->partialStub('seekPosition=' . $seekPosition);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: EXIT!');
        }
 
        /**
@@ -124,7 +185,12 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         */
        public function size () {
                // Call the iterator instance
-               return $this->getIteratorInstance()->size();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: CALLED!');
+               $size = $this->getIteratorInstance()->size();
+
+               // Return size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: size=%d - EXIT!', $size));
+               return $size;
        }
 
 }