From 92968f97201d354a7063a56ab6baa38306922618 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 3 Mar 2023 10:07:20 +0100 Subject: [PATCH 1/1] Continued: - added more debug lines - added a few more checks on parameters - moved EXCEPTION_NULL_POINTER to FrameworkInterface --- .../classes/class_BaseFrameworkSystem.php | 7 +- .../user/class_UserDatabaseFrontend.php | 4 +- .../binary/class_BaseBinaryFile.php | 267 +++++++++--------- .../binary/index/class_IndexFile.php | 48 ++-- .../binary/stack/class_StackFile.php | 46 +-- .../class_BaseAbstractFile.php | 44 ++- .../file_directories/class_BaseFileIo.php | 2 +- .../class_FrameworkDirectoryPointer.php | 34 ++- .../class_FrameworkRawFileInputPointer.php | 18 +- .../class_FrameworkTextFileInputPointer.php | 14 +- .../class_FrameworkFileInputOutputPointer.php | 45 +-- .../io_stream/class_FileIoStream.php | 82 ++++-- .../class_FrameworkRawFileOutputPointer.php | 11 +- .../class_FrameworkTextFileOutputPointer.php | 2 +- .../payment/class_PaymentDiscoveryFilter.php | 2 +- .../main/classes/helper/class_BaseHelper.php | 2 +- .../html/links/class_HtmlLinkHelper.php | 2 +- .../registry/class_RegistryIterator.php | 2 +- .../mailer/debug/class_DebugMailer.php | 2 +- .../registry/object/class_ObjectRegistry.php | 2 +- .../interfaces/class_FrameworkInterface.php | 1 + .../debug/class_DebugMiddleware.php | 10 +- 22 files changed, 359 insertions(+), 288 deletions(-) diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 431c3a10..2200b370 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -91,7 +91,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac ***********************/ // @todo Try to clean these constants up - const EXCEPTION_IS_NULL_POINTER = 0x001; const EXCEPTION_IS_NO_OBJECT = 0x002; const EXCEPTION_IS_NO_ARRAY = 0x003; const EXCEPTION_MISSING_METHOD = 0x004; @@ -711,7 +710,7 @@ Loaded includes: /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance[]=%s', gettype($this->getResultInstance()))); if (!$this->getResultInstance() instanceof SearchableResult) { // Throw an exception here - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Rewind it @@ -767,7 +766,7 @@ Loaded includes: /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance))); if (is_null($resultInstance)) { // Then the user instance is no longer valid (expired cookies?) - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get current array @@ -818,7 +817,7 @@ Loaded includes: /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: resultInstance[]=%s', gettype($resultInstance))); if (is_null($resultInstance)) { // Then the user instance is no longer valid (expired cookies?) - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get current array diff --git a/framework/main/classes/database/frontend/user/class_UserDatabaseFrontend.php b/framework/main/classes/database/frontend/user/class_UserDatabaseFrontend.php index c0cae135..fc8348ad 100644 --- a/framework/main/classes/database/frontend/user/class_UserDatabaseFrontend.php +++ b/framework/main/classes/database/frontend/user/class_UserDatabaseFrontend.php @@ -113,7 +113,7 @@ class UserDatabaseFrontend extends BaseDatabaseFrontend implements ManageableAcc // Is this null? if (is_null($updateInstance)) { // Throw an exception here - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get search instance from update instance @@ -122,7 +122,7 @@ class UserDatabaseFrontend extends BaseDatabaseFrontend implements ManageableAcc // Is it still null? if (is_null($searchInstance)) { // Throw an exception here - throw new NullPointerException($updateInstance, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($updateInstance, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } } diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index a7a1dcfd..cb53584f 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -96,7 +96,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function __construct (string $className) { // Call parent constructor + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: className=%s - CALLED!', $className)); parent::__construct($className); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FRAMEWORK-DIRECTORY-POINTER: EXIT!'); } /** @@ -106,7 +110,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return void */ private function setBackBuffer (string $backBuffer) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting backBuffer(%d)=%s - CALLED!', strlen($backBuffer), $backBuffer)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Setting backBuffer(%d)=%s - CALLED!', strlen($backBuffer), $backBuffer)); $this->backBuffer = $backBuffer; } @@ -116,7 +120,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return $backBuffer Characters "stored" in back-buffer */ private function getBackBuffer () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Getting this->backBuffer(%d)=%s - CALLED!', strlen($this->backBuffer), $this->backBuffer)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Getting this->backBuffer(%d)=%s - CALLED!', strlen($this->backBuffer), $this->backBuffer)); return $this->backBuffer; } @@ -127,7 +131,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return void */ private function setCurrentBlock (string $currentBlock) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting currentBlock(%d)=%s - CALLED!', strlen($currentBlock), $currentBlock)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Setting currentBlock(%d)=%s - CALLED!', strlen($currentBlock), $currentBlock)); $this->currentBlock = $currentBlock; } @@ -137,7 +141,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return $current Currently read data */ public function getCurrentBlock () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Getting this->currentBlock(%d)=%s - CALLED!', strlen($this->currentBlock), $this->currentBlock)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Getting this->currentBlock(%d)=%s - CALLED!', strlen($this->currentBlock), $this->currentBlock)); return $this->currentBlock; } @@ -147,7 +151,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return $totalEntries Size of file header */ public final function getHeaderSize () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Getting this->headerSize=%d - CALLED!', $this->headerSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Getting this->headerSize=%d - CALLED!', $this->headerSize)); return $this->headerSize; } @@ -158,7 +162,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return void */ public final function setHeaderSize (int $headerSize) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting headerSize=%d - CALLED!', $headerSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Setting headerSize=%d - CALLED!', $headerSize)); $this->headerSize = $headerSize; } @@ -189,7 +193,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return $seekPosition Current seek position (stored here in object) */ public final function getSeekPosition () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Getting this->seekPosition=%d - CALLED!', $this->seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Getting this->seekPosition=%d - CALLED!', $this->seekPosition)); return $this->seekPosition; } @@ -200,7 +204,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @return void */ protected final function setSeekPosition (int $seekPosition) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting seekPosition=%d - CALLED!', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Setting seekPosition=%d - CALLED!', $seekPosition)); $this->seekPosition = $seekPosition; } @@ -213,24 +217,24 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function isFileGapsOnly () { // Count every gap - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $gapsSize = 0; - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->gaps()=%d', count($this->gaps))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->gaps()=%d', count($this->gaps))); foreach ($this->gaps as $gap) { // Calculate size of found gap: end-start including both - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gap[%s]=%d,ga[%s]=%d', BinaryFile::GAPS_INDEX_START, $gap[BinaryFile::GAPS_INDEX_START], BinaryFile::GAPS_INDEX_END, $gap[BinaryFile::GAPS_INDEX_END])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: gap[%s]=%d,ga[%s]=%d', BinaryFile::GAPS_INDEX_START, $gap[BinaryFile::GAPS_INDEX_START], BinaryFile::GAPS_INDEX_END, $gap[BinaryFile::GAPS_INDEX_END])); $gapsSize += ($gap[BinaryFile::GAPS_INDEX_END] - $gap[BinaryFile::GAPS_INDEX_START]); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d', $gapsSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: gapsSize=%d', $gapsSize)); } // Total gap size + header size + 1 must be same as file size - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d,this->headerSize=%d,this->fileSize=%d', $gapsSize, $this->getHeaderSize(), $this->getFileSize())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: gapsSize=%d,this->headerSize=%d,this->fileSize=%d', $gapsSize, $this->getHeaderSize(), $this->getFileSize())); $determinedFileSize = ($gapsSize + $this->getHeaderSize() + 1); // Should not be more! - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: determinedFileSize=%d,this->fileSize=%d', $determinedFileSize, $this->getFileSize())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: determinedFileSize=%d,this->fileSize=%d', $determinedFileSize, $this->getFileSize())); if ($determinedFileSize > $this->getFileSize()) { // Should not happen throw new OutOfBoundsException(sprintf('determinedFileSize=%d is larger than this->fileSize=%d', $determinedFileSize, $this->getFileSize())); @@ -240,7 +244,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $isGapsOnly = ($determinedFileSize == $this->getFileSize()); // Return flag - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isGapsOnly=%d - EXIT!', intval($isGapsOnly))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: isGapsOnly=%d - EXIT!', intval($isGapsOnly))); return $isGapsOnly; } @@ -253,26 +257,26 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ private function markFileGapsOnly (string $type, int $minimumBlockLength) { // Is config cache there? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength)); if (!isset(self::$configCache[$type . '_pre_allocate_count'])) { // Then set it self::$configCache[$type . '_pre_allocate_count'] = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count'); } // Very simple to do ... - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: self:configCache[%s_pre_allocate_count]()=%d', count(self::$configCache[$type . '_pre_allocate_count']))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: self:configCache[%s_pre_allocate_count]()=%d', count(self::$configCache[$type . '_pre_allocate_count']))); for ($idx = 0; $idx < self::$configCache[$type . '_pre_allocate_count']; $idx++) { // Calculate start/end positions $startPosition = $idx * $minimumBlockLength; $endPosition = $idx * $minimumBlockLength + $minimumBlockLength; // Mark start and end position as gap - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->addGap(%d, %d) ...', $startPosition, $endPosition)); $this->addGap($startPosition, $endPosition); } // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -284,14 +288,14 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ private function addGap(int $startPosition, int $endPosition) { // Push to gaps array - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: startPosition=%d,endPosition=%d - CALLED!', $startPosition, $endPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: startPosition=%d,endPosition=%d - CALLED!', $startPosition, $endPosition)); array_push($this->gaps, [ BinaryFile::GAPS_INDEX_START => $startPosition, BinaryFile::GAPS_INDEX_END => $endPosition, ]); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -301,11 +305,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ private function initBackBuffer () { // Simply call the setter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $this->setBackBuffer(''); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -317,22 +321,22 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function rewindUpdateSeekPosition (bool $flushHeader = false) { // Seek to beginning of file - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d - CALLED!', intval($flushHeader))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: flushHeader=%d - CALLED!', intval($flushHeader))); $this->rewind(); // And update seek position ... - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->updateSeekPosition() ...'); $this->updateSeekPosition(); // Flush headers? if ($flushHeader) { // ... to write it back into the file - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->flushFileHeader() ...'); $this->flushFileHeader(); } // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -342,11 +346,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function seekToOldPosition () { // Seek to currently ("old") saved position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $this->seek($this->determineSeekPosition()); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -357,15 +361,15 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function initFile (SplFileInfo $fileInfoInstance) { // Get a file i/o pointer instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance)); $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileInfoInstance)); // ... and set it here - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting pointerInstance=%s ...', $pointerInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: Setting pointerInstance=%s ...', $pointerInstance->__toString())); $this->setPointerInstance($pointerInstance); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -377,21 +381,21 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function markCurrentBlockAsEmpty (int $length) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); if ($length < 1) { // Length cannot below one - throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); + throw new InvalidArgumentException(sprintf('length=%d is not valid', $length), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Get current seek position $currentPosition = $this->determineSeekPosition(); // Now add it as gap entry - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ..', ($currentPosition - $length), $currentPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->addGap(%d, %d) ..', ($currentPosition - $length), $currentPosition)); $this->addGap(($currentPosition - $length), $currentPosition); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -404,18 +408,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function initCountersGapsArray () { // Init counter and seek position to header size - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->determineSeekPosition() - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->determineSeekPosition() - CALLED!'); $seekPosition = $this->getSeekPosition(); // Set counter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); $this->setCounter(0); // Get header size $headerSize = $this->getHeaderSize(); // Set it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->seekPosition=%d ...', $headerSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: Setting this->seekPosition=%d ...', $headerSize)); $this->setSeekPosition($headerSize); // Init arrays @@ -423,11 +427,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $this->damagedEntries = []; // Seek back to old position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->seek(%d) ...', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->seek(%d) ...', $seekPosition)); $this->seek($seekPosition); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -437,15 +441,15 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function updateSeekPosition () { // Get key (= seek position) - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $seekPosition = $this->determineSeekPosition(); // And set it here - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); $this->setSeekPosition($seekPosition); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -457,7 +461,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public static function isBlockSeparatorFound (string $str) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: str=%s - CALLED!', $str)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: str=%s - CALLED!', $str)); if (empty($str)) { // Throw IAE throw new InvalidArgumentException('Parameter "str" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -467,7 +471,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $isFound = (strpos($str, chr(BinaryFile::SEPARATOR_ENTRIES)) !== false); // Return result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isFound=%d - EXIT!', intval($isFound))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: isFound=%d - EXIT!', intval($isFound))); return $isFound; } @@ -483,7 +487,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function writeData (int $seekPosition, string $data, bool $flushHeader = true) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader))); if ($seekPosition < 0) { // Invalid seek position throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition)); @@ -493,31 +497,31 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { } // Write data at given position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,%s) ...', $seekPosition, $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->writeAtPosition(%d,%s) ...', $seekPosition, $data)); $this->writeAtPosition($seekPosition, $data); // Increment counter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->incrementCounter() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->incrementCounter() ...'); $this->incrementCounter(); // Update seek position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->updateSeekPosition() ...'); $this->updateSeekPosition(); // Flush the header? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d', intval($flushHeader))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: flushHeader=%d', intval($flushHeader))); if ($flushHeader === true) { // Flush header - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->flushFileHeader() ...'); $this->flushFileHeader(); // Seek to old position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->seekToOldPosition() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->seekToOldPosition() ...'); $this->seekToOldPosition(); } // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -531,7 +535,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function writeAtPosition (int $seekPosition, string $dataStream) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream)); if ($seekPosition < 0) { // Invalid seek position throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition)); @@ -541,11 +545,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { } // Call pointer's method - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->pointerInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->pointerInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream)); $status = $this->getPointerInstance()->writeAtPosition($seekPosition, $dataStream); // Return status - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: status[%s]=%d - EXIT!', gettype($status), $status)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: status[%s]=%d - EXIT!', gettype($status), $status)); return $status; } @@ -556,7 +560,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function isFileHeaderInitialized () { // Default is not initialized - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $isInitialized = false; // Is the file initialized? @@ -565,19 +569,19 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $this->rewind(); // Read file header - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->readFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->readFileHeader() ...'); $this->readFileHeader(); // Get header count $headerCount = count($this->getHeader()); // The above method does already check the header - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: headerCount=%d', $headerCount)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: headerCount=%d', $headerCount)); $isInitialized = ($headerCount > 0); } // Return result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized))); return $isInitialized; } @@ -589,14 +593,14 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function isFileInitialized () { // Get it from iterator which holds the pointer instance. If false is returned - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $fileSize = $this->size(); /* * The returned file size should not be false or NULL as this means * that the pointer class does not work correctly. */ - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize[%s]=%d', gettype($fileSize), $fileSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: fileSize[%s]=%d', gettype($fileSize), $fileSize)); if (!is_int($fileSize)) { // Bad file? throw new UnexpectedValueException(sprintf('fileSize[]=%s is unexpected', gettype($fileSize)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE); @@ -606,7 +610,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $isInitialized = ($fileSize > 0); // Return result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized))); return $isInitialized; } @@ -618,23 +622,23 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function createFileHeader () { // The file's header should not be initialized here - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); if ($this->isFileHeaderInitialized()) { // Bad method call //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, TRUE))); - throw new BadMethodCallException('File header is already initialized but method called'); + throw new BadMethodCallException('File header is already initialized but method called', FrameworkInterface::EXCEPTION_BAD_METHOD_CALL); } // Simple flush file header which will create it. - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->flushFileHeader() ...'); $this->flushFileHeader(); // Rewind seek position (to beginning of file) and update/flush file header - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewindUpdateSeekPosition() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->rewindUpdateSeekPosition() ...'); $this->rewindUpdateSeekPosition(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -644,11 +648,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function determineSeekPosition () { // Call pointer instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $seekPosition = $this->getPointerInstance()->determineSeekPosition(); // Return position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d - EXIT!', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d - EXIT!', $seekPosition)); return $seekPosition; } @@ -662,7 +666,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function seek (int $offset, int $whence = SEEK_SET) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: offset=%d,whence=%d - CALLED!', $offset, $whence)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: offset=%d,whence=%d - CALLED!', $offset, $whence)); if ($offset < 0) { // No offset is smaller than zero throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset)); @@ -672,7 +676,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $status = $this->getPointerInstance()->seek($offset, $whence); // Return status - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: status[%s]=%d - EXIT!', gettype($status), $status)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: status[%s]=%d - EXIT!', gettype($status), $status)); return $status; } @@ -685,22 +689,22 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function read (int $bytes = 0) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: bytes=%d - CALLED!', $bytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: bytes=%d - CALLED!', $bytes)); if ($bytes < 0) { // Throw exception throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes)); } // Call pointer instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->pointerInstance->read(%d) ...', $bytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->pointerInstance->read(%d) ...', $bytes)); $data = $this->getPointerInstance()->read($bytes); // Update seek position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->updateSeekPosition() ...'); $this->updateSeekPosition(); // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]=%s - EXIT!', gettype($data), $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: data[%s]=%s - EXIT!', gettype($data), $data)); return $data; } @@ -711,11 +715,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function rewind () { // Call pointer instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); $this->getPointerInstance()->rewind(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -728,59 +732,59 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function analyzeFileStructure () { // Make sure the file is initialized - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: CALLED!'); if (!$this->isFileInitialized()) { // Bad method call - throw new BadMethodCallException('Method called but file is not initialized.'); + throw new BadMethodCallException('Method called but file is not initialized.', FrameworkInterface::EXCEPTION_BAD_METHOD_CALL); } // Init counters and gaps array - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->initCounterGapsArrays() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->initCounterGapsArrays() ...'); $this->initCountersGapsArray(); // Output message (as this may take some time) - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Analyzing file structure ... (this may take some time)')); + self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('Analyzing file structure ... (this may take some time)')); // First Seek to right after file header - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->seek(%d) ...', $this->getHeaderSize() + 1)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->seek(%d) ...', $this->getHeaderSize() + 1)); $this->seek($this->getHeaderSize() + 1); // Then try to load all entries - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, looping through file ...', $this->getSeekPosition())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, looping through file ...', $this->getSeekPosition())); while ($this->isValid()) { // Get current entry $current = $this->getCurrentBlock(); // Go to next entry - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current=%s, calling this->readNextBlock() ...', $current)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: current=%s, Invoking this->readNextBlock() ...', $current)); $this->readNextBlock(); /* * If the block is empty, maybe the whole file is? This could mean * that the file has been pre-allocated. */ - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current(%d)[]=%s', strlen($current), gettype($current))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: current(%d)[]=%s', strlen($current), gettype($current))); if (empty(trim($current, chr(0)))) { // Then skip this part - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current[]=%s is empty - CONTINUE!', gettype($current))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: current[]=%s is empty - CONTINUE!', gettype($current))); continue; } // Handle current record - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current(%d)[%s]=%s', strlen($current), gettype($current), $current)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: current(%d)[%s]=%s', strlen($current), gettype($current), $current)); } // If the last read block is empty, check gaps - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current()=%d', strlen($current))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: current()=%d', strlen($current))); if (empty(trim($current, chr(0)))) { // Output message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Found a total of %d gaps.', count($this->gaps))); + self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: Found a total of %d gaps.', count($this->gaps))); // Check gaps, if the whole file is empty. - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isFileGapsOnly() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->isFileGapsOnly() ...'); if ($this->isFileGapsOnly()) { // Only gaps, so don't continue here. - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: File is gaps-only - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('BASE-BINARY-FILE: File is gaps-only - EXIT!'); return; } } @@ -791,15 +795,15 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * defragmentation is to far in the past, or if a "hard" limit has * reached, run defragmentation. */ - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isDefragmentationNeeded() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->isDefragmentationNeeded() ...'); if ($this->isDefragmentationNeeded()) { // Run "defragmentation" - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->doRunDefragmentation() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->doRunDefragmentation() ...'); $this->doRunDefragmentation(); } // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -812,10 +816,10 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function readNextBlockByLength (int $length) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,length=%d - CALLED!', $this->getSeekPosition(), $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,length=%d - CALLED!', $this->getSeekPosition(), $length)); if ($length < 1) { // Throw IAE - throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); + throw new InvalidArgumentException(sprintf('length=%d is not valid', $length), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Read possibly back-buffered bytes from previous call of next(). @@ -826,21 +830,21 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * "block" may not fit, so this loop will continue until the EOB or EOF * has been reached whatever comes first. */ - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data))); while ((!$this->isEndOfFileReached()) && (empty($data) || !self::isBlockSeparatorFound($data))) { // Then read the next possible block - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->read(%d) ...', $this->getSeekPosition(), $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, Invoking this->read(%d) ...', $this->getSeekPosition(), $length)); $block = $this->read($length); // Is the block empty? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%d', strlen($block), $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: block()=%d,length=%d', strlen($block), $length)); if (strlen($block) == 0) { // Read empty block, maybe EOF - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, block is empty, maybe EOF reached - BREAK!', $this->getSeekPosition())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, block is empty, maybe EOF reached - BREAK!', $this->getSeekPosition())); break; } elseif (empty(trim($block, chr(0)))) { // Mark it as empty - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->markCurrentBlockAsEmpty(%d) ...', $this->getSeekPosition(), $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, Invoking this->markCurrentBlockAsEmpty(%d) ...', $this->getSeekPosition(), $length)); $this->markCurrentBlockAsEmpty($length); } @@ -848,22 +852,22 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $data .= $block; // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data))); } /* * Init back-buffer which is the data that has been found beyond the * separator. */ - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->initBackBuffer(), clearing this->currentBlock ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->initBackBuffer(), clearing this->currentBlock ...'); $this->initBackBuffer(); $this->setCurrentBlock(''); // Is $data empty? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data(%d)=%s', strlen($data), $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: data(%d)=%s', strlen($data), $data)); if (empty(trim($data, chr(0)))) { // Yes, maybe whole file was ... - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, maybe empty file found - EXIT!', $this->getSeekPosition())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, maybe empty file found - EXIT!', $this->getSeekPosition())); return; } @@ -871,19 +875,19 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $dataArray = explode(chr(BinaryFile::SEPARATOR_ENTRIES), $data); // Left part is the actual block, right one the back-buffer data, if found - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray))); - //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray))); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true))); $this->setCurrentBlock($dataArray[0]); // Is back buffere data found? if (isset($dataArray[1]) && !empty(trim($dataArray[1], chr(0)))) { // Set back buffer - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->backBuffer=%s ...', $dataArray[1])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: Setting this->backBuffer=%s ...', $dataArray[1])); $this->setBackBuffer($dataArray[1]); } // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -892,20 +896,19 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { * @param $type Type of the file * @return void * @throws InvalidArgumentException If a parameter is empty - * @throws BadMethodCallException If this->stackInstance is not properly set */ protected function preAllocateFileByTypeLength (string $type, int $minimumBlockLength) { // Is it enabled? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength)); if (empty($type)) { // Empty type throw new InvalidArgumentException('Parameter "type" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif ($minimumBlockLength < 1) { // Invalid block length - throw new InvalidArgumentException(sprintf('Parameter minimumBlockLength=%d is not valid', $minimumBlockLength)); + throw new InvalidArgumentException(sprintf('Parameter minimumBlockLength=%d is not valid', $minimumBlockLength), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (!FrameworkBootstrap::getConfigurationInstance()->isEnabled($type . '_pre_allocate')) { // Don't continue here. - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.')); + self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Not pre-allocating file. - EXIT!'); return; } @@ -913,31 +916,31 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $fileSize = $this->getFileSize(); // Calulcate seek position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minimumBlockLength=%d,fileSize=%d', $minimumBlockLength, $fileSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: minimumBlockLength=%d,fileSize=%d', $minimumBlockLength, $fileSize)); $seekPosition = $this->getHeaderSize() + $minimumBlockLength * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count') + $fileSize ; // Now simply write a NUL there. This will pre-allocate the file. - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,NUL) ...', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->writeAtPosition(%d,NUL) ...', $seekPosition)); $this->writeAtPosition($seekPosition, chr(0)); // Is the seek position zero? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%d', $fileSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: fileSize=%d', $fileSize)); if ($fileSize == 0) { // Mark file as gaps-only - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->markGapsOnly(%s,%d) ...', $type, $minimumBlockLength)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: Invoking this->markGapsOnly(%s,%d) ...', $type, $minimumBlockLength)); $this->markFileGapsOnly($type, $minimumBlockLength); } else { // Analyze file structure - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->analyzeFileStructure() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->analyzeFileStructure() ...'); $this->analyzeFileStructure(); } // Rewind seek position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: Invoking this->rewind() ...'); $this->rewind(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-BINARY-FILE: EXIT!'); } /** @@ -949,29 +952,29 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ protected function isValidByLength (int $length) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); if ($length < 1) { // Throw IAE - throw new InvalidArgumentException(sprintf('Parameter length=%d is not valid', $length)); + throw new InvalidArgumentException(sprintf('Parameter length=%d is not valid', $length), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Get current seek position $seekPosition = $this->determineSeekPosition(); // Then try to read it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition)); $data = $this->read($length); // If some bytes could be read, all is fine - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]()=%d', gettype($data), strlen($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: data[%s]()=%d', gettype($data), strlen($data))); $isValid = ((is_string($data)) && (strlen($data) > 0)); // Get header size - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d', intval($isValid))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: isValid=%d', intval($isValid))); $headerSize = $this->getHeaderSize(); // Is the seek position at or beyond the header? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,headerSize=%d', $seekPosition, $headerSize)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d,headerSize=%d', $seekPosition, $headerSize)); if ($seekPosition >= $headerSize) { // Seek back to old position $isValid = ($isValid && $this->seek($seekPosition) === 0); @@ -981,7 +984,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { } // Return result - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d - EXIT!', intval($isValid))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: isValid=%d - EXIT!', intval($isValid))); return $isValid; } @@ -1012,10 +1015,10 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { */ public function searchNextGap (int $length) { // If the file is only gaps, no need to seek - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length)); if ($length <= 0) { // Throw IAE - throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); + throw new InvalidArgumentException(sprintf('length=%d is not valid', $length), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif ($this->isFileGapsOnly()) { /* * The first empty block is the 2nd one right after the header, so @@ -1024,7 +1027,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $seekPosition = ($this->getHeaderSize() + 2); // Return position - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d - EXIT!', $seekPosition)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-BINARY-FILE: seekPosition=%d - EXIT!', $seekPosition)); return $seekPosition; } diff --git a/framework/main/classes/file_directories/binary/index/class_IndexFile.php b/framework/main/classes/file_directories/binary/index/class_IndexFile.php index df36ffbd..28ca8b1b 100644 --- a/framework/main/classes/file_directories/binary/index/class_IndexFile.php +++ b/framework/main/classes/file_directories/binary/index/class_IndexFile.php @@ -58,7 +58,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public final static function createIndexFile (SplFileInfo $fileInfoInstance, Indexable $indexInstance) { // Get a new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,indexInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $indexInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,indexInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $indexInstance->__toString())); $indexFileInstance = new IndexFile(); // Set file instance here for callbacks @@ -74,7 +74,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { $indexFileInstance->initCountersGapsArray(); // Return the prepared instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: indexFileInstance=%s - EXIT!', $indexFileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: indexFileInstance=%s - EXIT!', $indexFileInstance->__toString())); return $indexFileInstance; } @@ -86,18 +86,18 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public function flushFileHeader () { // Validate call - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: CALLED!'); if (!($this->getIndexInstance() instanceof Indexable)) { // Index instance not set throw new BadMethodCallException('this->indexInstance[] is not properly set.'); } // Call block instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Invoking this->indexInstance->flushFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('INDEX-FILE: Invoking this->indexInstance->flushFileHeader() ...'); $this->getIndexInstance()->flushFileHeader(); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: EXIT!'); } /** @@ -110,7 +110,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public function preAllocateFile (string $type) { // Is it enabled? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: type=%s - CALLED!', $type)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: type=%s - CALLED!', $type)); if (empty($type)) { // Empty type throw new InvalidArgumentException('Parameter "type" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -120,17 +120,17 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { } // Message to user - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Pre-allocating file ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('INDEX-FILE: Pre-allocating file ...'); // Calculate minimum block length $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength(); // Call protected method - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking this->preAllocateFileByTypeLength(%s,%d) ...', $type, $minimumBlockLength)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: Invoking this->preAllocateFileByTypeLength(%s,%d) ...', $type, $minimumBlockLength)); $this->preAllocateFileByTypeLength($type, $minimumBlockLength); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: EXIT!'); } /** @@ -142,22 +142,22 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public function isValid () { // Validate call - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: CALLED!'); if (!($this->getIndexInstance() instanceof Indexable)) { // Index instance not set throw new BadMethodCallException('this->indexInstance[] is not properly set.'); } // Get length from index - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Invoking this->indexInstance->calculateMinimumBlockLength() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: Invoking this->indexInstance->calculateMinimumBlockLength() ...'); $length = $this->getIndexInstance()->calculateMinimumBlockLength(); // Call protected method - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking this->isValidByLength(%d) ...', $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: Invoking this->isValidByLength(%d) ...', $length)); $isValid = $this->isValidByLength($length); // Return result - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: isValid=%d - EXIT!', intval($isValid))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: isValid=%d - EXIT!', intval($isValid))); return $isValid; } @@ -170,15 +170,15 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ protected function readNextBlock () { // First calculate minimum block length - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition())); $length = $this->getIndexInstance()->calculateMinimumBlockLength(); // Call protected method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking parent::readNextBlockByLength(%d) ...', $length)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: Invoking parent::readNextBlockByLength(%d) ...', $length)); parent::readNextBlockByLength($length); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: EXIT!'); } /** @@ -188,11 +188,11 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public function readFileHeader () { // Call index class' method - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Invoking this->indexInstance->readIndexHeader() - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: Invoking this->indexInstance->readIndexHeader() - CALLED!'); $this->getIndexInstance()->readIndexHeader(); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: EXIT!'); } /** @@ -206,7 +206,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { */ public function writeValueToFile (string $stackName, $value) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('INDEX-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value))); if (empty($stackName)) { // Throw IAE throw new InvalidArgumentException('Parameter "stackName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -219,19 +219,19 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { } // Encode/convert the value into a "binary format" - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking StringUtils::encodeData(value[]=%s) ...', gettype($value))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: Invoking StringUtils::encodeData(value[]=%s) ...', gettype($value))); $encoded = StringUtils::encodeData($value); // Get a strong hash for the "encoded" data - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: encoded(%d)=%s', strlen($encoded), $encoded)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('INDEX-FILE: encoded(%d)=%s', strlen($encoded), $encoded)); $hash = CryptoUtils::hash($encoded); // Then write it to the next free gap - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: hash=%s', $hash)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('INDEX-FILE: hash=%s', $hash)); $data = $this->getIndexInstance()->writeDataToFreeGap($stackName, $hash, $encoded); // Return info - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: data[]=%s - EXIT!', gettype($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('INDEX-FILE: data[]=%s - EXIT!', gettype($data))); return $data; } @@ -245,7 +245,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile { * @throws UnsupportedOperationException If this method is called */ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) { - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded)); + self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('INDEX-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded)); throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/framework/main/classes/file_directories/binary/stack/class_StackFile.php b/framework/main/classes/file_directories/binary/stack/class_StackFile.php index b3f27e4b..4f3c5b5e 100644 --- a/framework/main/classes/file_directories/binary/stack/class_StackFile.php +++ b/framework/main/classes/file_directories/binary/stack/class_StackFile.php @@ -59,7 +59,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public final static function createStackFile (SplFileInfo $infoInstance, StackableFile $stackInstance) { // Get a new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: infoInstance[%s]=%s,stackInstance=%s - CALLED!', get_class($infoInstance), $infoInstance, $stackInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: infoInstance[%s]=%s,stackInstance=%s - CALLED!', get_class($infoInstance), $infoInstance, $stackInstance->__toString())); $stackFileInstance = new StackFile(); // Set stack instance here for callbacks @@ -72,7 +72,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { $stackFileInstance->initCountersGapsArray(); // Return the prepared instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: stackFileInstance=%s - EXIT!', $stackFileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: stackFileInstance=%s - EXIT!', $stackFileInstance->__toString())); return $stackFileInstance; } @@ -84,18 +84,18 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public function flushFileHeader () { // Validate call - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: CALLED!'); if (!($this->getStackInstance() instanceof StackableFIle)) { // Index instance not set throw new BadMethodCallException('this->stackInstance[] is not properly set.'); } // Call block instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Invoking this->indexInstance->flushFileHeader() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: Invoking this->indexInstance->flushFileHeader() ...'); $this->getStackInstance()->flushFileHeader(); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: EXIT!'); } /** @@ -108,7 +108,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public function preAllocateFile (string $type) { // Is it enabled? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: type=%s - CALLED!', $type)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: type=%s - CALLED!', $type)); if (empty($type)) { // Empty type throw new InvalidArgumentException('Parameter "type" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -118,7 +118,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { } // Message to user - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Pre-allocating file ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('STACK-FILE: Pre-allocating file ...'); // Calculate minimum block length and get file size $minimumBlockLength = $this->getStackInstance()->calculateMinimumBlockLength(); @@ -127,7 +127,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { $this->preAllocateFileByTypeLength($type, $minimumBlockLength); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: EXIT!'); } /** @@ -139,22 +139,22 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public function isValid () { // Validate call - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: CALLED!'); if (!($this->getStackInstance() instanceof StackableFile)) { // Index instance not set throw new BadMethodCallException('this->stackInstance[] is not properly set.'); } // Get length from index - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Invoking this->stackInstance->calculateMinimumBlockLength() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: Invoking this->stackInstance->calculateMinimumBlockLength() ...'); $length = $this->getStackInstance()->calculateMinimumBlockLength(); // Call protected method - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Invoking this->isValidByLength(%d) ...', $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('STACK-FILE: Invoking this->isValidByLength(%d) ...', $length)); $isValid = $this->isValidByLength($length); // Return result - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: isValid=%d - EXIT!', intval($isValid))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: isValid=%d - EXIT!', intval($isValid))); return $isValid; } @@ -166,11 +166,11 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public function readFileHeader () { // Call stacke instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Invoking this->stackInstance->readStackHeader() - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: Invoking this->stackInstance->readStackHeader() - CALLED!'); $this->getStackInstance()->readStackHeader(); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: EXIT!'); } /** @@ -182,15 +182,15 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ protected function readNextBlock () { // First calculate minimum block length - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition())); $length = $this->getStackInstance()->calculateMinimumBlockLength(); // Call protected method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Invoking parent::readNextBlockByLength(%d) ...', $length)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: Invoking parent::readNextBlockByLength(%d) ...', $length)); parent::readNextBlockByLength($length); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: EXIT!'); } /** @@ -203,7 +203,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { */ public function writeValueToFile (string $stackName, $value) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value))); if (empty($stackName)) { // Throw IAE throw new InvalidArgumentException('Parameter "stackName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -213,19 +213,19 @@ class StackFile extends BaseBinaryFile implements FileStacker { } // Encode/convert the value into a "binary format" - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Invoking StringUtils::encodeData(value[]=%s) ...', gettype($value))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: Invoking StringUtils::encodeData(value[]=%s) ...', gettype($value))); $encoded = StringUtils::encodeData($value); // Get a strong hash for the "encoded" data - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Invoking CryptoUtils::hash(%s) ...', $encoded)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: Invoking CryptoUtils::hash(%s) ...', $encoded)); $hash = CryptoUtils::hash($encoded); // Then write it to the next free gap - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Invoking this->stackInstance->writeDataToFreeGap(%s,%s,%s) ...', $stackName, $hash, $encoded)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: Invoking this->stackInstance->writeDataToFreeGap(%s,%s,%s) ...', $stackName, $hash, $encoded)); $data = $this->getStackInstance()->writeDataToFreeGap($stackName, $hash, $encoded); // Return info - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: data[]=%s - EXIT!', gettype($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('STACK-FILE: data[]=%s - EXIT!', gettype($data))); return $data; } @@ -239,7 +239,7 @@ class StackFile extends BaseBinaryFile implements FileStacker { * @throws UnsupportedOperationException If this method is called */ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) { - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded)); + self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('STACK-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded)); throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/framework/main/classes/file_directories/class_BaseAbstractFile.php b/framework/main/classes/file_directories/class_BaseAbstractFile.php index f80e39e3..2e0aefe4 100644 --- a/framework/main/classes/file_directories/class_BaseAbstractFile.php +++ b/framework/main/classes/file_directories/class_BaseAbstractFile.php @@ -5,9 +5,13 @@ namespace Org\Mxchange\CoreFramework\Filesystem\File; // Import framework stuff use Org\Mxchange\CoreFramework\Filesystem\CloseableFile; use Org\Mxchange\CoreFramework\Filesystem\FilePointer; +use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; +// Import SPL stuff +use \InvalidArgumentException; + /** * An abstract file class * @@ -49,7 +53,11 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ protected function __construct (string $className) { // Call parent constructor + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-ABSTRACT-FILE: className=%s - CONSTRUCTED!', $className)); parent::__construct($className); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: EXIT!'); } /** @@ -84,7 +92,11 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ protected final function unsetPointerInstance () { // Simply invoke setter with no parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); $this->setPointerInstance(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: EXIT!'); } /** @@ -94,10 +106,14 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public final function __destruct() { // Try to close a file + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: DESTRUCTED!'); $this->closeFile(); // Call the parent destructor parent::__destruct(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: EXIT!'); } /** @@ -107,6 +123,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public function getFileSize () { // Call pointer instanze + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getPointerInstance()->getFileSize(); } @@ -117,7 +134,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public final function getCounter () { // Get it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Getting this->totalEntries=%d ... - CALLED!', $this->totalEntries)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-ABSTRACT-FILE: Getting this->totalEntries=%d ... - CALLED!', $this->totalEntries)); return $this->totalEntries; } @@ -129,7 +146,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ protected final function setCounter (int $counter) { // Set it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Setting this->totalEntries=%d ... - CALLED!', $counter)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-ABSTRACT-FILE: Setting this->totalEntries=%d ... - CALLED!', $counter)); $this->totalEntries = $counter; } @@ -139,12 +156,12 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * @return void */ protected final function incrementCounter () { - // Get it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!'); + // Count up + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); $this->totalEntries++; // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: EXIT!'); } /** @@ -153,6 +170,8 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * @return $fileObject An instance of a SplFileObject */ public final function getFileObject () { + // Call pointer instanze + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getPointerInstance()->getFileObject(); } @@ -161,6 +180,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public final function getFilename () { // Invole file object's method + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getFileObject()->getFilename(); } @@ -172,11 +192,11 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public function closeFile () { // Close down pointer instance as well by unsetting it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); $this->unsetPointerInstance(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: EXIT!'); } /** @@ -187,6 +207,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public function size () { // Call pointer instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getPointerInstance()->size(); } @@ -200,6 +221,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public function readFromFile () { // Call pointer instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getPointerInstance()->readFromFile(); } @@ -214,6 +236,13 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * an invalid file resource */ public function writeToFile (string $dataStream) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-ABSTRACT-FILE: dataStream()=%d - CALLED!', strlen($dataStream))); + if (empty($dataStream)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "dataStream" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Call pointer instance return $this->getPointerInstance()->writeToFile($dataStream); } @@ -225,6 +254,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint */ public final function isEndOfFileReached () { // Call pointer instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!'); return $this->getPointerInstance()->isEndOfFileReached(); } diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index c934ecb5..d093dda0 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -90,7 +90,7 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FILE-IO: fileName=%s - CALLED!', $this->getFileObject()->getPathname())); if (is_null($this->getFileObject())) { // Pointer not initialized - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION); diff --git a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php index 5386a528..f080e328 100644 --- a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -61,6 +61,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework */ public function __destruct() { // Is there a resource pointer? Then we have to close the directory here! + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FRAMEWORK-DIRECTORY-POINTER: DESTRUCTED!'); if ($this->getDirectoryIteratorInstance() instanceof DirectoryIterator) { // Try to close a directory $this->closeDirectory(); @@ -68,6 +69,9 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework // Call the parent destructor parent::__destruct(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FRAMEWORK-DIRECTORY-POINTER: EXIT!'); } /** @@ -83,6 +87,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework */ public static final function createFrameworkDirectoryPointer (string $pathName) { // Some pre-sanity checks... + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FRAMEWORK-DIRECTORY-POINTER: pathName=%s - CALLED!', $pathName)); if (empty($pathName)) { // Throw IAE throw new InvalidArgumentException('Parameter "pathName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -108,7 +113,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework $pointerInstance->setPathName($pathName); // Return the instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: Opened pathName=' . $pathName . ' - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -119,14 +124,14 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework */ public function readRawDirectory () { // Can the next entry be read? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: CALLED!'); assert($this->getDirectoryIteratorInstance()->valid()); // Read data from the directory pointer and return it $currentEntry = $this->getDirectoryIteratorInstance()->current(); // Return found entry - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: currentEntry[%s]=%s - EXIT!', gettype($currentEntry), $currentEntry)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: currentEntry[%s]=%s - EXIT!', gettype($currentEntry), $currentEntry)); return $currentEntry; } @@ -135,17 +140,17 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework * * @param $except Some parts of a directory we want to ignore. Valid: directory and file names, other values will be silently ignored * @return SplFileInfo An instance of a SplFileInfo class + * @throws InvalidArgumentException If a parameter has an invalid value */ public function readDirectoryExcept (array $except = []) { // No exceptions given? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: except()=%d - CALLED!', count($except))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: except()=%d - CALLED!', count($except))); if (count($except) == 0) { // No exception given, so read all files and directories, but not recursive - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: No exceptions given, please use readRawDirectory() instead!'); - return $this->readRawDirectory(); + throw new InvalidArgumentException('Parameter "except" is an empty array', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (!$this->getDirectoryIteratorInstance()->valid()) { // No more left to read - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: EOD reached - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: EOD reached - EXIT!'); return NULL; } @@ -156,26 +161,26 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework $currentEntry = $this->readRawDirectory(); // Shall we exclude directories? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: currentEntry[]=%s', gettype($currentEntry))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: currentEntry[]=%s', gettype($currentEntry))); if (is_object($currentEntry)) { // Get file name $fileInfoInstance = $currentEntry; // Is it a dot-directory or excluded? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot()))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot()))); while ($this->getDirectoryIteratorInstance()->valid() && ($this->getDirectoryIteratorInstance()->isDot() || in_array($fileInfoInstance->getFilename(), $except))) { // Update current instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot()))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DIRECTORY-POINTER: fileInfoInstance->filename=%s,isDot=%d', $fileInfoInstance->getFilename(), intval($this->getDirectoryIteratorInstance()->isDot()))); $fileInfoInstance = $this->readRawDirectory(); // To next entry - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: Invoking directoryIteratorInstance->next() ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('DIRECTORY-POINTER: Invoking directoryIteratorInstance->next() ...'); $this->getDirectoryIteratorInstance()->next(); } } // Return read line - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DIRECTORY-POINTER: fileInfoInstance[%s]=%s - EXIT!', gettype($fileInfoInstance), $fileInfoInstance)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DIRECTORY-POINTER: fileInfoInstance[%s]=%s - EXIT!', gettype($fileInfoInstance), $fileInfoInstance)); return $fileInfoInstance; } @@ -187,9 +192,12 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework */ public function closeDirectory () { // Close the directory by unsetting it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: CALLED!'); $this->unsetDirectoryIteratorInstance(); $this->setPathName(''); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DIRECTORY-POINTER: CALLED!'); } /** diff --git a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php index 71eed4d4..4ba33c57 100644 --- a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php +++ b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php @@ -65,7 +65,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { */ public static final function createFrameworkRawFileInputPointer (SplFileInfo $fileInstance) { // Some pre-sanity checks... - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) { // File cannot be accessed (due to open_basedir restriction) throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE); @@ -81,21 +81,21 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { $fileObject = $fileInstance->openFile('rb'); // Is it valid? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('RAW-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); if (!($fileObject instanceof SplFileObject)) { // Something bad happend throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // Create new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileObject.pathname=%s', $fileObject->getPathname())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('RAW-FILE-INPUT-POINTER: fileObject.pathname=%s', $fileObject->getPathname())); $pointerInstance = new FrameworkRawFileInputPointer(); // Set file pointer and file name $pointerInstance->setFileObject($fileObject); // Return the instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -108,17 +108,17 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { */ public function readFromFile () { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-FILE-INPUT-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!'); if (is_null($this->getFileObject())) { // Pointer not initialized - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION); } // Read data from the file pointer and return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-FILE-INPUT-POINTER: Invoking this->read(1024) - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: Invoking this->read(1024) - EXIT!'); return $this->read(1024); } @@ -143,7 +143,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { */ public function read (int $bytes = 0) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: bytes=%d - CALLED!', $bytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: bytes=%d - CALLED!', $bytes)); if ($bytes < 0) { // Throw IAE throw new InvalidArgumentException(sprintf('bytes=%d is an invalid value, only zero or postive numbers are accepted', $bytes)); @@ -159,7 +159,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { } // Then return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: data()=%d - EXIT!', strlen($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: data()=%d - EXIT!', strlen($data))); return $data; } diff --git a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php index d113df5d..1805d7c8 100644 --- a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -62,7 +62,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { */ public static final function createFrameworkTextFileInputPointer (SplFileInfo $fileInstance) { // Check parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) { // File cannot be reached throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE); @@ -78,7 +78,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { $fileObject = $fileInstance->openFile('r'); // Is it valid? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TEXT-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); if (!($fileObject instanceof SplFileObject)) { // Something bad happend throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); @@ -91,7 +91,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { $pointerInstance->setFileObject($fileObject); // Return the instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TEXT-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -102,6 +102,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { */ public function readFromFile () { // Read 1024 Byte data from the file pointer and return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!'); return $this->read(1024); } @@ -112,6 +113,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { */ public function readLine () { // Read whole line from the file pointer and return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!'); return $this->read(); } @@ -126,12 +128,13 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { */ public function read (int $bytes = 0) { // Some sanity checks + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: bytes=%d - CALLED!', $bytes)); if ($bytes < 0) { // Cannot be below zero throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes)); } elseif (is_null($this->getFileObject())) { // Pointer not initialized - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION); @@ -140,13 +143,16 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { // Is $bytes set? if ($bytes > 0) { // Try to read given characters + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: Invoking this->fileObject->fread(%d) ...', $bytes)); $data = $this->getFileObject()->fread($bytes); } else { // Try to read whole line + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: Invoking this->fileObject->fgets() ...'); $data = $this->getFileObject()->fgets(); } // Then return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-INPUT-POINTER: data()=%d - EXIT!', strlen($data))); return $data; } diff --git a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php index ed4c49e1..2a03a011 100644 --- a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -67,7 +67,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public static final function createFrameworkFileInputOutputPointer (SplFileInfo $fileInstance) { // Some pre-sanity checks... - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance)); if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) { // File exists but cannot be read throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE); @@ -86,7 +86,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP $fileObject = $fileInstance->openFile('c+b'); // Is it valid? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: fileObject[]=%s', gettype($fileObject))); if (!($fileObject instanceof SplFileObject)) { // Something bad happend throw new FileIoException($fileInstance->getPathname(), self::EXCEPTION_FILE_POINTER_INVALID); @@ -99,7 +99,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP $pointerInstance->setFileObject($fileObject); // Return the instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -110,11 +110,11 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function readFromFile () { // Read data from the file pointer and return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!'); $data = $this->read(1024); // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%d - EXIT!', gettype($data), $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%d - EXIT!', gettype($data), $data)); return $data; } @@ -126,7 +126,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function writeToFile (string $dataStream) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: dataStream(%d)=%s - CALLED!', strlen($dataStream), $dataStream)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: dataStream(%d)=%s - CALLED!', strlen($dataStream), $dataStream)); if (empty($dataStream)) { // Empty dataStream throw new InvalidArgumentException('Parameter "dataStream" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -136,11 +136,11 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP $length = strlen($dataStream); // Write data to the file pointer and return written bytes - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: Invoking this->fileObject->fwrite(%s,%d) ...', $dataStream, $length)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: Invoking this->fileObject->fwrite(%s,%d) ...', $dataStream, $length)); $status = $this->getFileObject()->fwrite($dataStream, $length); // Return status - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); return $status; } @@ -155,7 +155,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function writeAtPosition (int $seekPosition, string $dataStream) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream)); if ($seekPosition < 0) { // Invalid seek position throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition)); @@ -168,11 +168,11 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP } // Then write the data at that position - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: Invoking this->writeToFile(%s) ...', $dataStream)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: Invoking this->writeToFile(%s) ...', $dataStream)); $status = $this->writeToFile($dataStream); // Return status - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); return $status; } @@ -183,11 +183,11 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function rewind () { /// Rewind the pointer - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!'); $this->getFileObject()->rewind(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: EXIT!'); } /** @@ -200,17 +200,20 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function seek (int $seekPosition, int $whence = SEEK_SET) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence)); if ($seekPosition < 0) { // Invalid seek position throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition)); + } elseif ($whence < 0) { + // Invalid seek position + throw new OutOfBoundsException(sprintf('whence=%d is not valid.', $whence)); } // Move the file pointer $status = $this->getFileObject()->fseek($seekPosition, $whence); // Return status - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status)); return $status; } @@ -221,11 +224,11 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function readLine () { // Read whole line - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!'); $data = $this->read(); // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data)); return $data; } @@ -238,7 +241,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function read (int $bytes = 0) { // Validatre parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes)); if ($bytes < 0) { // Bytes cannot be lesser than zero throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes)); @@ -254,7 +257,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP } // Then return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data)); return $data; } @@ -309,7 +312,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP */ public function getFileSize () { // Get file's data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!'); $fileData = $this->getFileObject()->fstat(); // Make sure the required array key is there @@ -319,7 +322,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP } // Return size - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: fileData[size]=%d - EXIT!', $fileData['size'])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-INPUT-OUTPUT-POINTER: fileData[size]=%d - EXIT!', $fileData['size'])); return $fileData['size']; } diff --git a/framework/main/classes/file_directories/io_stream/class_FileIoStream.php b/framework/main/classes/file_directories/io_stream/class_FileIoStream.php index 126ab896..9a82005c 100644 --- a/framework/main/classes/file_directories/io_stream/class_FileIoStream.php +++ b/framework/main/classes/file_directories/io_stream/class_FileIoStream.php @@ -77,9 +77,11 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil */ public static final function createFileIoStream () { // Create new instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-STREAM: CALLED!'); $ioInstance = new FileIoStream(); // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: ioInstance=%s - EXIT!', $ioInstance->__toString())); return $ioInstance; } @@ -95,7 +97,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil */ public final function saveFile (SplFileInfo $fileInfoInstance, array $dataArray) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: fileInfoInstance=%s,dataArray()=%d - CALLED!', $fileInfoInstance, count($dataArray))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: fileInfoInstance=%s,dataArray()=%d - CALLED!', $fileInfoInstance, count($dataArray))); if (count($dataArray) < 2) { // Not valid array, at least 2 elements must be there! throw new InvalidArgumentException(sprintf('Parameter "dataArray" should have at least 2 elements, has %d', count($dataArray))); @@ -116,7 +118,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil } // Write a header information for validation purposes - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Writing header to fileInstance=%s ...', $fileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Writing header to fileInstance=%s ...', $fileInstance->__toString())); $fileInstance->writeToFile(sprintf('%s%s%s%s%s%s%s%s%s' . PHP_EOL, self::FILE_IO_FILE_HEADER_ID, self::FILE_IO_SEPARATOR, @@ -130,7 +132,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil )); // Encode the (maybe) binary stream with Base64 - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Encoding %d bytes to BASE64 string ...', strlen($dataArray[1]))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Encoding %d bytes to BASE64 string ...', strlen($dataArray[1]))); $b64Stream = base64_encode($dataArray[1]); // write the data line-by-line @@ -140,7 +142,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil $line = substr($b64Stream, $idx, 50); // Save it to the stream - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Writing %d bytes to file ...', strlen($line))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Writing %d bytes to file ...', strlen($line))); $fileInstance->writeToFile(sprintf('%s%s%s%s%s' . PHP_EOL, self::FILE_IO_DATA_BLOCK_ID, self::FILE_IO_SEPARATOR, @@ -154,10 +156,11 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil } // Close the file + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('FILE-IO-STREAM: Closing file ...'); unset($fileInstance); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-IO-STREAM: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-STREAM: EXIT!'); } /** @@ -169,7 +172,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil */ public final function loadFileContents (SplFileInfo $infoInstance) { // Initialize some variables and arrays - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: infoInstance=%s - CALLED!', $infoInstance)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: infoInstance=%s - CALLED!', $infoInstance)); $inputBuffer = ''; $lastBuffer = ''; $header = []; @@ -180,16 +183,16 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($infoInstance)); // Read all it's contents (we very and transparently decompress it below) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: fileInstance=%s', $fileInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: fileInstance=%s', $fileInstance->__toString())); while ($readRawLine = $fileInstance->readFromFile()) { // Add the read line to the buffer - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Adding %d read bytes to input buffer.', strlen($readRawLine))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Adding %d read bytes to input buffer.', strlen($readRawLine))); $inputBuffer .= $readRawLine; // Break infinite loop maybe caused by the input handler if ($lastBuffer == $inputBuffer) { // Break out of loop, EOF reached? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-IO-STREAM: EOF reached!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('FILE-IO-STREAM: EOF reached!'); break; } @@ -198,23 +201,24 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil } // Close directory handle + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('FILE-IO-STREAM: Closing file ...'); unset($fileInstance); // Convert it into an array - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Read inputBuffer=%d bytes from infoInstance=%s', strlen($inputBuffer), $infoInstance)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Read inputBuffer=%d bytes from infoInstance=%s', strlen($inputBuffer), $infoInstance)); $inputArray = explode(chr(10), $inputBuffer); // Now process the read lines and verify it's content - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: inputArray()=%d', count($inputArray))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: inputArray()=%d', count($inputArray))); foreach ($inputArray as $rawLine) { // Trim it a little but not the leading spaces/tab-stops $rawLine = rtrim($rawLine); // Analyze this line - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: rawLine()=%d', strlen($rawLine))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: rawLine()=%d', strlen($rawLine))); if (substr($rawLine, 0, 5) == self::FILE_IO_FILE_HEADER_ID) { // Header found, so let's extract it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Found header, rawLine=%s', $rawLine)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Found header, rawLine=%s', $rawLine)); $header = explode(self::FILE_IO_SEPARATOR, $rawLine); $headerLine = trim($header[1]); @@ -222,14 +226,14 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil $header = explode(self::FILE_IO_CHUNKER, $headerLine); // Is the header (maybe) valid? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: header()=%d', count($header))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: header()=%d', count($header))); if (count($header) != 4) { // Throw an exception - throw new InvalidArrayCountException(array($this, 'header', count($header), 4), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + throw new InvalidArrayCountException([$this, 'header', count($header), 4], self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); } } elseif (substr($rawLine, 0, 5) == self::FILE_IO_DATA_BLOCK_ID) { // Is a data line! - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Data line found rawLine=%s', $rawLine)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Data line found rawLine=%s', $rawLine)); $data = explode(self::FILE_IO_SEPARATOR, $rawLine); $dataLine = $data[1]; @@ -237,68 +241,69 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil $data = explode(self::FILE_IO_CHUNKER, $dataLine); // Validate the read line - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: data()=%d', count($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: data()=%d', count($data))); if (count($data) == 2) { // Generate checksum (MD5 is okay here) $checksum = md5($data[0]); // Check if it matches provided one - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: checksum=%s,data[1]=%s', $checksum, $data[1])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: checksum=%s,data[1]=%s', $checksum, $data[1])); if ($checksum != $data[1]) { // MD5 hash did not match! - throw new InvalidMD5ChecksumException(array($this, $checksum, $data[1]), self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); + throw new InvalidMD5ChecksumException([$this, $checksum, $data[1]], self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); } } else { // Invalid count! - throw new InvalidArrayCountException(array($this, 'data', count($data), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + throw new InvalidArrayCountException([$this, 'data', count($data), 2], self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); } // Add this to the readData string - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Adding %d raw data to input stream', strlen($data[0]))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Adding %d raw data to input stream', strlen($data[0]))); $readData .= $data[0]; } else { // Other raw lines than header/data tagged lines and re-add the new-line char - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: Adding rawLine=%s(%d) + PHP_EOL to input stream', $rawLine, strlen($rawLine))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Adding rawLine=%s(%d) + PHP_EOL to input stream', $rawLine, strlen($rawLine))); $readData .= $rawLine . PHP_EOL; } } // Was raw lines read and no header/data? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: readData()=%d,header()=%d,data()=%d', strlen($readData), count($header), count($data))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: readData()=%d,header()=%d,data()=%d', strlen($readData), count($header), count($data))); if ((!empty($readData)) && (count($header) == 0) && (count($data) == 0)) { // Return raw lines back - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: readData()=%d - EXIT!', strlen($readData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: readData()=%d - EXIT!', strlen($readData))); return $readData; } // Was a header found? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: header()=%d', count($header))); if (count($header) != 4) { // Throw an exception - throw new InvalidArrayCountException(array($this, 'header', count($header), 4), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + throw new InvalidArrayCountException([$this, 'header', count($header), 4], self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); } // Decode all from Base64 $decodedData = @base64_decode($readData); // Does the size match? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: decodedData()=%d,header[2]=%d', strlen($decodedData), $header[2])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: decodedData()=%d,header[2]=%d', strlen($decodedData), $header[2])); if (strlen($decodedData) != $header[2]) { // Size did not match - throw new InvalidDataLengthException(array($this, strlen($decodedData), $header[2]), self::EXCEPTION_UNEXPECTED_STRING_SIZE); + throw new InvalidDataLengthException([$this, strlen($decodedData), $header[2]], self::EXCEPTION_UNEXPECTED_STRING_SIZE); } // Generate checksum from whole read data $checksum = md5($decodedData); // Validate the decoded data with the final MD5 hash - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: checksum=%s,header[3]=%s', $checksum, $header[3])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: checksum=%s,header[3]=%s', $checksum, $header[3])); if ($checksum != $header[3]) { // MD5 hash did not match! - throw new InvalidMD5ChecksumException(array($this, $checksum, $header[3]), self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); + throw new InvalidMD5ChecksumException([$this, $checksum, $header[3]], self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); } // Return all in an array - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-IO-STREAM: header()=%d,decodedData()=%d - EXIT!', count($header), strlen($decodedData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: header()=%d,decodedData()=%d - EXIT!', count($header), strlen($decodedData))); return [ 'header' => $header, 'data' => $decodedData, @@ -313,7 +318,8 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil * @throws UnsupportedOperationException If this method is called */ public function streamData (string $data) { - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); + // Not supported + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: data=()=%d - CALLED!', strlen($data))); throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION); } @@ -324,6 +330,8 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil * @todo 0% done */ public function determineSeekPosition () { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-STREAM: CALLED!'); DebugMiddleware::getSelfInstance()->partialStub(); } @@ -335,6 +343,16 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil * @return $status Status of file seek: 0 = success, -1 = failed */ public function seek (int $offset, int $whence = SEEK_SET) { + // Check parameters + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: offset=%d,whence=%d - CALLED!', $offset, $whence)); + if ($offset < 0) { + // Throw IAE + throw new InvalidArgumentException(sprintf('offset=%d is below zero', $offset), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } elseif ($whence < 0) { + // Throw IAE + throw new InvalidArgumentException(sprintf('whence=%d is below zero', $whence), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + DebugMiddleware::getSelfInstance()->partialStub('offset=' . $offset . ',whence=' . $whence); } @@ -344,6 +362,8 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil * @return $size Size (in bytes) of file */ public function size () { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-STREAM: CALLED!'); DebugMiddleware::getSelfInstance()->partialStub(); } diff --git a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php index 61eb1705..6d2c3a26 100644 --- a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php @@ -59,14 +59,14 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer */ public static final function createFrameworkRawFileOutputPointer (SplFileInfo $fileInstance, string $mode) { // Is the parameter valid? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: fileInstance=%s,mode=%s - CALLED!', $fileInstance->__toString(), $mode)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: fileInstance=%s,mode=%s - CALLED!', $fileInstance->__toString(), $mode)); if (empty($mode)) { // No fileInstance given throw new InvalidArgumentException('Parameter "mode" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Try to open a handler - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: Invoking fileInstance->openFile(%s) ...', $mode)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: Invoking fileInstance->openFile(%s) ...', $mode)); $fileObject = $fileInstance->openFile($mode); // Is it valid? @@ -85,7 +85,7 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer $pointerInstance->setFileObject($fileObject); // Return the instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -100,19 +100,20 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer */ public function writeToFile (string $dataStream) { // Validate parameter and class own attributes - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: dataStream(%d)=%s (trimmed) - CALLED!', strlen($dataStream), trim($dataStream))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: dataStream(%d)=%s (trimmed) - CALLED!', strlen($dataStream), trim($dataStream))); if (empty($dataStream)) { // Empty data stream throw new InvalidArgumentException('Parameter "dataStream" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getFileObject())) { // Pointer not initialized - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION); } // Write data to the file pointer and return written bytes + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: Invoking this->fileObject->fwrite(dataStream()=%d - EXIT!', strlen($dataStream))); return $this->getFileObject()->fwrite($dataStream); } diff --git a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php index bf1657c4..f6587257 100644 --- a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php @@ -103,7 +103,7 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer throw new InvalidArgumentException('Parameter "dataStream" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getFileObject())) { // Pointer not initialized - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid object! throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION); diff --git a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php index 7299f4f7..1536aec8 100644 --- a/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php +++ b/framework/main/classes/filter/payment/class_PaymentDiscoveryFilter.php @@ -72,7 +72,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable { // Is the resolver set? if (is_null($resolverInstance)) { // Throw an exception here - throw new NullPointerException($filterInstance, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($filterInstance, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get the action name from resolver diff --git a/framework/main/classes/helper/class_BaseHelper.php b/framework/main/classes/helper/class_BaseHelper.php index 0651d0c1..b6545819 100644 --- a/framework/main/classes/helper/class_BaseHelper.php +++ b/framework/main/classes/helper/class_BaseHelper.php @@ -597,7 +597,7 @@ abstract class BaseHelper extends BaseFrameworkSystem { // The $valueInstance attribute should not be null! if (is_null($this->getValueInstance())) { // Throws an exception here - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Is the field set? diff --git a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php index f4b0ffe6..170a3092 100644 --- a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php +++ b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php @@ -93,7 +93,7 @@ class HtmlLinkHelper extends BaseHtmlHelper implements HelpableTemplate { // Sanity-check on it if (is_null($requestInstance)) { // Throw an exception here - throw new NullPointerException($helperInstance, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($helperInstance, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get page (this will throw an exception if not set) diff --git a/framework/main/classes/iterator/registry/class_RegistryIterator.php b/framework/main/classes/iterator/registry/class_RegistryIterator.php index 94640bac..731c61ac 100644 --- a/framework/main/classes/iterator/registry/class_RegistryIterator.php +++ b/framework/main/classes/iterator/registry/class_RegistryIterator.php @@ -250,7 +250,7 @@ class RegistryIterator extends BaseIterator implements IteratableRegistry { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('REGISTRY-ITERATOR[%s]: registryKey=%s,current[]=%s', $this->key(), $registryKey, gettype($current))); if (is_null($current)) { // This cannot happen and indicates a logic error - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Return it diff --git a/framework/main/classes/mailer/debug/class_DebugMailer.php b/framework/main/classes/mailer/debug/class_DebugMailer.php index 3d34d045..884b3858 100644 --- a/framework/main/classes/mailer/debug/class_DebugMailer.php +++ b/framework/main/classes/mailer/debug/class_DebugMailer.php @@ -108,7 +108,7 @@ class DebugMailer extends BaseMailer implements DeliverableMail { // Is the value instance there? if (!isset($recipientList['values'][$variable])) { // Throw exception - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get the field from the value instance diff --git a/framework/main/classes/registry/object/class_ObjectRegistry.php b/framework/main/classes/registry/object/class_ObjectRegistry.php index 8d25922f..0d01db6d 100644 --- a/framework/main/classes/registry/object/class_ObjectRegistry.php +++ b/framework/main/classes/registry/object/class_ObjectRegistry.php @@ -163,7 +163,7 @@ class ObjectRegistry extends BaseRegistry implements ObjectRegister { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('OBJECT-REGISTRY: Invoking this->instanceExists(%s) ...', $instanceKey)); if (!$this->instanceExists($instanceKey)) { // This might happen if a non-registered key was requested - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Get the instance diff --git a/framework/main/interfaces/class_FrameworkInterface.php b/framework/main/interfaces/class_FrameworkInterface.php index 836bba5e..8c1003d5 100644 --- a/framework/main/interfaces/class_FrameworkInterface.php +++ b/framework/main/interfaces/class_FrameworkInterface.php @@ -35,6 +35,7 @@ interface FrameworkInterface { const EXCEPTION_CLASS_NOT_FOUND = 0x204; const EXCEPTION_BAD_METHOD_CALL = 0x205; const EXCEPTION_OUT_OF_BOUNDS = 0x206; + const EXCEPTION_IS_NULL_POINTER = 0x207; /** * Getter for field name diff --git a/framework/main/middleware/debug/class_DebugMiddleware.php b/framework/main/middleware/debug/class_DebugMiddleware.php index 53a2ece6..d5ec854d 100644 --- a/framework/main/middleware/debug/class_DebugMiddleware.php +++ b/framework/main/middleware/debug/class_DebugMiddleware.php @@ -198,7 +198,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger { throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getOutputInstance())) { // Should not be NULL - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Use debug output handler @@ -230,7 +230,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger { throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getOutputInstance())) { // Should not be NULL - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Use debug output handler @@ -262,7 +262,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger { throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getOutputInstance())) { // Should not be NULL - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Use debug output handler @@ -294,7 +294,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger { throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getOutputInstance())) { // Should not be NULL - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Use debug output handler @@ -352,7 +352,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger { throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (is_null($this->getOutputInstance())) { // Should not be NULL - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER); } // Invoke Inner method -- 2.39.2