From 728805fb9d82980b98f0f301410c1c500c7aac7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 7 Dec 2020 11:57:31 +0100 Subject: [PATCH] Continued: - renamed BaseStacker/BaseFileStack->addValue() to addValueToStack() - added more debug lines - added more parameter validation - updated index.php MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../file_directories/class_BaseFileIo.php | 5 +- .../index/file_stack/class_FileStackIndex.php | 16 +- .../iterator/file/class_FileIterator.php | 222 ++++++++++++++++-- .../classes/stacker/class_BaseStacker.php | 2 +- .../stacker/fifo/class_FiFoStacker.php | 4 +- .../stacker/file/class_BaseFileStack.php | 2 +- .../stacker/file/fifo/class_FiFoFileStack.php | 4 +- .../stacker/filo/class_FiLoStacker.php | 4 +- index.php | 12 +- 9 files changed, 227 insertions(+), 44 deletions(-) diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index 54ab1dbf..4a024c8d 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -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 diff --git a/framework/main/classes/index/file_stack/class_FileStackIndex.php b/framework/main/classes/index/file_stack/class_FileStackIndex.php index 2a0efa3a..efb563cc 100644 --- a/framework/main/classes/index/file_stack/class_FileStackIndex.php +++ b/framework/main/classes/index/file_stack/class_FileStackIndex.php @@ -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 diff --git a/framework/main/classes/iterator/file/class_FileIterator.php b/framework/main/classes/iterator/file/class_FileIterator.php index 98aae71f..a246927c 100644 --- a/framework/main/classes/iterator/file/class_FileIterator.php +++ b/framework/main/classes/iterator/file/class_FileIterator.php @@ -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; } } diff --git a/framework/main/classes/stacker/class_BaseStacker.php b/framework/main/classes/stacker/class_BaseStacker.php index 9d857e75..1a81dbeb 100644 --- a/framework/main/classes/stacker/class_BaseStacker.php +++ b/framework/main/classes/stacker/class_BaseStacker.php @@ -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)) { diff --git a/framework/main/classes/stacker/fifo/class_FiFoStacker.php b/framework/main/classes/stacker/fifo/class_FiFoStacker.php index aafe1178..d74166ff 100644 --- a/framework/main/classes/stacker/fifo/class_FiFoStacker.php +++ b/framework/main/classes/stacker/fifo/class_FiFoStacker.php @@ -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!'); diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index d1484b31..54205230 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -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)) { diff --git a/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php b/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php index 4fec8355..f2fce745 100644 --- a/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php +++ b/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php @@ -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!'); diff --git a/framework/main/classes/stacker/filo/class_FiLoStacker.php b/framework/main/classes/stacker/filo/class_FiLoStacker.php index bc70761f..06b9985b 100644 --- a/framework/main/classes/stacker/filo/class_FiLoStacker.php +++ b/framework/main/classes/stacker/filo/class_FiLoStacker.php @@ -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!'); diff --git a/index.php b/index.php index a881011a..46f5db5e 100644 --- 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'); -- 2.39.5