]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 10:57:31 +0000 (11:57 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 10:57:31 +0000 (11:57 +0100)
- renamed BaseStacker/BaseFileStack->addValue() to addValueToStack()
- added more debug lines
- added more parameter validation
- updated index.php

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/class_BaseFileIo.php
framework/main/classes/index/file_stack/class_FileStackIndex.php
framework/main/classes/iterator/file/class_FileIterator.php
framework/main/classes/stacker/class_BaseStacker.php
framework/main/classes/stacker/fifo/class_FiFoStacker.php
framework/main/classes/stacker/file/class_BaseFileStack.php
framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php
framework/main/classes/stacker/filo/class_FiLoStacker.php
index.php

index 54ab1dbfc9de8fef64687649b61e10f27735320f..4a024c8db034886df850e49137ebef9bb3ff6bce 100644 (file)
@@ -166,16 +166,15 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         * @todo        Handle seekStatus
         */
        public function size () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
                // Get current seek position
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
                $seekPosition = $this->determineSeekPosition();
 
                // Seek to end
                $seekStatus = $this->seek(0, SEEK_END);
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekStatus=%d', __METHOD__, __LINE__, $seekStatus));
 
                // Get position again (which is the end of the file)
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekStatus=%d', __METHOD__, __LINE__, $seekStatus));
                $size = $this->determineSeekPosition();
 
                // Reset seek position to old
index 2a0efa3a944a309f59e376f152b9ba6f221ef81a..efb563cc2da5cfe9032ec99f1496c91ce24a989a 100644 (file)
@@ -12,6 +12,7 @@ use Org\Mxchange\CoreFramework\Stack\Index\IndexableStack;
 // Import SPL stuff
 use \InvalidArgumentException;
 use \SplFileInfo;
+use \UnexpectedValueException;
 
 /**
  * A FileStack index class
@@ -71,6 +72,7 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
         * @param       $groupId        Name of stack to add hash for
         * @param       $data           Hash and gap position to be added to the index
         * @return      void
+        * @throws      UnexpectedValueException        If an invalid gap position is being returned
         */
        public function addHashToIndex (string $groupId, array $data) {
                // Raw data been written to the file
@@ -85,17 +87,19 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                        $data[StackableFile::ARRAY_NAME_DATA_LENGTH]
                );
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
-
                // Search for next free gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
                $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
 
-               // Gap position cannot be smaller than header length + 1
-               assert($gapPosition > $this->getIteratorInstance()->getHeaderSize());
+               // Gap position cannot be smaller or equal than header length
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
+               if ($gapPosition <= ($this->getIteratorInstance()->getHeaderSize() + 1)) {
+                       // Not valid gap position returned
+                       throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is smaller or equal headerSize+1=%d', gettype($gapPosition), $gapPosition, ($this->getIteratorInstance()->getHeaderSize() + 1)));
+               }
 
                // Then write the data at that gap
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeData(%d,%s) ...', $gapPosition, $rawData));
                $this->getIteratorInstance()->writeData($gapPosition, $rawData);
 
                // Trace message
index 98aae71f26f73052519bb16dd2956abb0ab58fed..a246927c02e4585c810e0af7eb4d7743d8f12c6f 100644 (file)
@@ -7,6 +7,10 @@ use Org\Mxchange\CoreFramework\Filesystem\Block;
 use Org\Mxchange\CoreFramework\Iterator\BaseIterator;
 use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
 
+// Import SPL stuff
+use \BadMethodCallException;
+use \InvalidArgumentException;
+
 /**
  * A file iterator
  *
@@ -48,18 +52,19 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
        /**
         * Creates an instance of this class
         *
-        * @param       $pointerInstance        An instance of a Block class
+        * @param       $blockInstance  An instance of a Block class
         * @return      $iteratorInstance       An instance of a Iterator class
         */
        public final static function createFileIterator (Block $blockInstance) {
                // Get new instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: blockInstance=%s - CALLED!', $blockInstance->__toString()));
                $iteratorInstance = new FileIterator();
 
                // Set the instance here
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d] Setting blockInstance=%s ...', __METHOD__, __LINE__, $blockInstance->__toString()));
                $iteratorInstance->setBlockInstance($blockInstance);
 
                // Return the prepared instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: iteratorInstance=%s - EXIT!', $iteratorInstance->__toString()));
                return $iteratorInstance;
        }
 
@@ -86,20 +91,44 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * Gets currently read data
         *
         * @return      $current        Currently read data
+        * @throws      BadMethodCallException  If valid() is FALSE
         */
        public function current () {
+               // Is condition given?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               if (!$this->valid()) {
+                       // Throw BMCE
+                       throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?');
+               }
+
                // Call block instance
-               return $this->getBlockInstance()->current();
+               $current = $this->getBlockInstance()->current();
+
+               // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: current[]=%s - EXIT!', gettype($current)));
+               return $current;
        }
 
        /**
         * Gets current seek position ("key").
         *
         * @return      $key    Current key in iteration
+        * @throws      BadMethodCallException  If valid() is FALSE
         */
        public function key () {
-               // Return it
-               return $this->getBlockInstance()->determineSeekPosition();
+               // Is condition given?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               if (!$this->valid()) {
+                       // Throw BMCE
+                       throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?');
+               }
+
+               // Get key from block instance
+               $key = $this->getBlockInstance()->determineSeekPosition();
+
+               // Return key
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: key[%s]=%s - EXIT!', gettype($key), $key));
+               return $key;
        }
 
        /**
@@ -109,7 +138,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function next () {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBlockInstance()->next();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -119,7 +152,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function rewind () {
                // Call block instance
-               return $this->getBlockInstance()->rewind();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $status = $this->getBlockInstance()->rewind();
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status)));
+               return $status;
        }
 
        /**
@@ -130,7 +168,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function valid () {
                // Call block instance
-               return $this->getBlockInstance()->valid();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $isValid = $this->getBlockInstance()->valid();
+
+               // Return flag
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isValid=%d - EXIT!', intval($isValid)));
+               return $isValid;
        }
 
        /**
@@ -138,10 +181,22 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         *
         * @param       $seekPosition   Seek position in file
         * @return      $status                 Status of this operation
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function seek (int $seekPosition) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - CALLED!', $seekPosition));
+               if ($seekPosition < 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+               }
+
                // Call block instance
-               return $this->getBlockInstance()->seek($seekPosition);
+               $status = $this->getBlockInstance()->seek($seekPosition);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status)));
+               return $status;
        }
 
        /**
@@ -151,9 +206,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function size () {
                // Call the block object
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $size = $this->getBlockInstance()->size();
 
-               // Return result
+               // Return size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
                return $size;
        }
 
@@ -164,8 +221,19 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @return      $data   Data read from file
         */
        public function read (int $bytes = 0) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: bytes=%d - CALLED!', $bytes));
+               if ($bytes < 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+               }
+
                // Call block instance
-               return $this->getBlockInstance()->read($bytes);
+               $data = $this->getBlockInstance()->read($bytes);
+
+               // Return data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
+               return $data;
        }
 
        /**
@@ -177,7 +245,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function analyzeFile () {
                // Just call the block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBlockInstance()->analyzeFile();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -187,7 +259,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function isFileHeaderInitialized () {
                // Just call the block instance
-               return $this->getBlockInstance()->isFileHeaderInitialized();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $isInitialized = $this->getBlockInstance()->isFileHeaderInitialized();
+
+               // Return flag
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isInitialized=%d - EXIT!', intval($isInitialized)));
+               return $isInitialized;
        }
 
        /**
@@ -197,7 +274,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function createFileHeader () {
                // Just call the block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBlockInstance()->createFileHeader();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -205,10 +286,21 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         *
         * @param       $type   Type of the file
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function preAllocateFile (string $type) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: type=%s - CALLED!', $type));
+               if (empty($type)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               }
+
                // Just call the block instance
                $this->getBlockInstance()->preAllocateFile($type);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -221,7 +313,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function initCountersGapsArray () {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBlockInstance()->initCountersGapsArray();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -231,7 +327,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public final function getHeaderSize () {
                // Call block instance
-               return $this->getBlockInstance()->getHeaderSize();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $size = $this->getBlockInstance()->getHeaderSize();
+
+               // Return size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
+               return $size;
        }
 
        /**
@@ -242,17 +343,26 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public final function setHeaderSize (int $headerSize) {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: headerSize=%d - CALLED!', $headerSize));
                $this->getBlockInstance()->setHeaderSize($headerSize);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
         * Getter for header array
         *
-        * @return      $totalEntries   Size of file header
+        * @return      $header         Header array
         */
        public final function getHeader () {
                // Call block instance
-               return $this->getBlockInstance()->getHeader();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $header = $this->getBlockInstance()->getHeader();
+
+               // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - EXIT!', count($header)));
+               return $header;
        }
 
        /**
@@ -263,7 +373,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public final function setHeader (array $header) {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - CALLED!', count($header)));
                $this->getBlockInstance()->setHeader($header);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -273,7 +387,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function updateSeekPosition () {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBlockInstance()->updateSeekPosition();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -283,7 +401,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public final function getCounter () {
                // Call block instance
-               return $this->getBlockInstance()->getCounter();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $counter = $this->getBlockInstance()->getCounter();
+
+               // Return counter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: counter=%d - EXIT!', $counter));
+               return $counter;
        }
 
        /**
@@ -293,7 +416,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function getFileSize () {
                // Call block instance
-               return $this->getBlockInstance()->getFileSize();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $size = $this->getBlockInstance()->getFileSize();
+
+               // Return size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
+               return $size;
        }
 
        /**
@@ -303,10 +431,24 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @param       $data                   Data to be written
         * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,data(%d)=%s,flushHeader=%d - CALLED!', $seekPosition, strlen($data), $data, intval($flushHeader)));
+               if ($seekPosition < 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+               } elseif (empty($data)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "data" is empty');
+               }
+
                // Call block instance
                $this->getBlockInstance()->writeData($seekPosition, $data, $flushHeader);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -316,7 +458,12 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function getSeekPosition () {
                // Call block instance
-               return $this->getBlockInstance()->getSeekPosition();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $seekPosition = $this->getBlockInstance()->getSeekPosition();
+
+               // Return position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - EXIT!', $seekPosition));
+               return $seekPosition;
        }
 
        /**
@@ -325,10 +472,25 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @param       $groupId        Group identifier
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeValueToFile (string $groupId, $value) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value)));
+               if (empty($groupId)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupId" is empty');
+               } elseif (is_resource($value) || is_object($value)) {
+                       // Resources and objects are nothing for file-based indexes (mostly)
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value)));
+               }
+
                // Call block instance
-               return $this->getBlockInstance()->writeValueToFile($groupId, $value);
+               $data = $this->getBlockInstance()->writeValueToFile($groupId, $value);
+
+               // Return data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
+               return $data;
        }
 
        /**
@@ -340,8 +502,15 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @return      $data           Gap position and length of the raw data
         */
        public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
+
                // Call block instance
-               return $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+               $data = $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+
+               // Return data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
+               return $data;
        }
 
        /**
@@ -350,11 +519,22 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         *
         * @param       $length                 Length of raw data
         * @return      $seekPosition   Found next gap's seek position
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public function searchNextGap (int $length) {
-               // Call block instance
+               // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: length=%d - CALLED!', $length));
-               return $this->getBlockInstance()->searchNextGap($length);
+               if ($length <= 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+               }
+
+               // Call block instance
+               $seekPosition = $this->getBlockInstance()->searchNextGap($length);
+
+               // Return position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - EXIT!', $seekPosition));
+               return $seekPosition;
        }
 
 }
index 9d857e75934f9322f4422bd82e4cc83be0f68aab..1a81dbebd3566ef2d6bd341f534b94ceb696ef96 100644 (file)
@@ -217,7 +217,7 @@ abstract class BaseStacker extends BaseFrameworkSystem {
         * @throws      BadMethodCallException  If given stack is missing
         * @throws      FullStackerException    Thrown if the stack is full
         */
-       protected function addValue (string $stackerName, $value) {
+       protected function addValueToStack (string $stackerName, $value) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
                if (empty($stackerName)) {
index aafe1178ac20adeb8539e3d436c37b9622b9206f..d74166ffc386eb36fccb0e8c222129d503d96123 100644 (file)
@@ -72,8 +72,8 @@ class FiFoStacker extends BaseStacker implements Stackable {
                }
 
                // Call the protected method
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
-               parent::addValue($stackerName, $value);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+               parent::addValueToStack($stackerName, $value);
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
index d1484b31cd27ae8d0d327935278a5c5981ca3c12..5420523056216d65d865035bbdf9a621e9f595c6 100644 (file)
@@ -271,7 +271,7 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
         * @throws      InvalidArgumentException        If a parameter is not valid
         * @throws      InvalidArgumentException        Not all variable types are wanted here
         */
-       protected function addValue (string $stackerName, $value) {
+       protected function addValueToStack (string $stackerName, $value) {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[%s]=%s - CALLED!', $stackerName, gettype($value), print_r($value, true)));
                if (empty($stackerName)) {
index 4fec83552a73c296c5ac1b94f1fbc6121f852fbf..f2fce745e502b828fc5ec4b02003a8b2079a6391 100644 (file)
@@ -94,8 +94,8 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
                }
 
                // 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);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Calling parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+               parent::addValueToStack($stackerName, $value);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: EXIT!');
index bc70761f17af67445c0a042cca9fc9208bfa1001..06b9985ba595b6fc386f3cf0355d5a7559329b6c 100644 (file)
@@ -71,8 +71,8 @@ class FiLoStacker extends BaseStacker implements Stackable {
                }
 
                // Call the protected method
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
-               parent::addValue($stackerName, $value);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: Calling parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+               parent::addValueToStack($stackerName, $value);
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILO-FILE-STACK: EXIT!');
index a881011a008250dd45f292ff3c7cc289d70b9d83..46f5db5e3db33873e9aabba507ef3140aeb84367 100644 (file)
--- a/index.php
+++ b/index.php
@@ -142,13 +142,13 @@ final class ApplicationEntryPoint {
                        // We only try this
                        try {
                                // Assign variables
-                               $templateInstance->assignVariable('message', $message);
-                               $templateInstance->assignVariable('code', $code);
-                               $templateInstance->assignVariable('extra', $extraData);
-                               $templateInstance->assignVariable('backtrace', $backtrace);
+                               $templateInstance->assignVariable('message'       , $message);
+                               $templateInstance->assignVariable('code'          , $code);
+                               $templateInstance->assignVariable('extra'         , $extraData);
+                               $templateInstance->assignVariable('backtrace'     , $backtrace);
                                $templateInstance->assignVariable('total_includes', ClassLoader::getSelfInstance()->getTotal());
-                               $templateInstance->assignVariable('total_objects', ObjectFactory::getTotal());
-                               $templateInstance->assignVariable('title', $languageInstance->getMessage('emergency_exit_title'));
+                               $templateInstance->assignVariable('total_objects' , ObjectFactory::getTotal());
+                               $templateInstance->assignVariable('title'         , $languageInstance->getMessage('emergency_exit_title'));
 
                                // Load the template
                                $templateInstance->loadCodeTemplate('emergency_exit');