From deb07dbc679f4cc7fe0e84eeb352f87f21ccf0aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 7 Jan 2021 21:18:27 +0100 Subject: [PATCH] Continued: - removed SeekableWritableFileIterator as this had no real function but only handled over the method calls to the inner class - for now on let's get the $binaryFileInstance directly from it MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../binary/class_BaseBinaryFile.php | 4 +- .../main/classes/index/class_BaseIndex.php | 1 - .../index/file/class_BaseFileIndex.php | 55 ++- .../index/file/stack/class_FileStackIndex.php | 2 +- .../iterator/file/class_FileIterator.php | 399 +----------------- .../command/class_BaseCommandResolver.php | 2 +- .../class_BaseControllerResolver.php | 13 +- .../class_ConsoleControllerResolver.php | 2 +- .../html/class_HtmlControllerResolver.php | 2 +- .../image/class_ImageControllerResolver.php | 2 +- .../stacker/file/class_BaseFileStack.php | 1 - .../class_SeekableWritableFileIterator.php | 201 --------- 12 files changed, 52 insertions(+), 632 deletions(-) delete mode 100644 framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index ac37fd24..d2adfe87 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -919,11 +919,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { // 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))); + /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true))); $this->setCurrentBlock($dataArray[0]); // Is back buffere data found? - if (!empty(trim($dataArray[1], chr(0)))) { + 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])); $this->setBackBuffer($dataArray[1]); diff --git a/framework/main/classes/index/class_BaseIndex.php b/framework/main/classes/index/class_BaseIndex.php index 7ee704ce..e0e68beb 100644 --- a/framework/main/classes/index/class_BaseIndex.php +++ b/framework/main/classes/index/class_BaseIndex.php @@ -7,7 +7,6 @@ use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; -use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait; diff --git a/framework/main/classes/index/file/class_BaseFileIndex.php b/framework/main/classes/index/file/class_BaseFileIndex.php index e25f37b2..d8f697a3 100644 --- a/framework/main/classes/index/file/class_BaseFileIndex.php +++ b/framework/main/classes/index/file/class_BaseFileIndex.php @@ -65,17 +65,21 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!'); $this->getIteratorInstance()->rewind(); + // Get header size + $headerSize = $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize(); + // Then read it (see constructor for calculation) - $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: headerSize=%d', $headerSize)); + $data = $this->getIteratorInstance()->getBinaryFileInstance()->read($headerSize); // Have all requested bytes been read? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize())); - if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize())); + if (strlen($data) != $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()) { // Invalid header length throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d', strlen($data), $data, - $this->getIteratorInstance()->getHeaderSize() + $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize() )); } elseif (empty(trim($data, chr(0)))) { // Empty file header @@ -94,7 +98,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // And update seek position /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...'); - $this->getIteratorInstance()->updateSeekPosition(); + $this->getIteratorInstance()->getBinaryFileInstance()->updateSeekPosition(); /* * Now split it: @@ -122,7 +126,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { $header[1] = hex2bin($header[1]); // Set it here - $this->getIteratorInstance()->setHeader($header); + $this->getIteratorInstance()->getBinaryFileInstance()->setHeader($header); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!'); @@ -144,7 +148,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), // Total entries - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), // Separator header<->entries chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) @@ -152,20 +156,20 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // Write it to disk (header is always at seek position 0) /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header)); - $this->getIteratorInstance()->writeAtPosition(0, $header); + $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition(0, $header); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!'); } /** - * Initializes this index + * Initializes this file-based index * * @param $fileInfoInstance An instance of a SplFileInfo class * @return void * @todo Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file. */ - protected function initIndex (SplFileInfo $fileInfoInstance) { + protected function initFileIndex (SplFileInfo $fileInfoInstance) { // Get a file i/o pointer instance for index file /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance)); $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this)); @@ -186,24 +190,24 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // Set it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Setting headerSize=%d ...', $headerSize)); - $this->getIteratorInstance()->setHeaderSize($headerSize); + $this->getIteratorInstance()->getBinaryFileInstance()->setHeaderSize($headerSize); // Init counters and gaps array /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...'); - $this->getIteratorInstance()->initCountersGapsArray(); + $this->getIteratorInstance()->getBinaryFileInstance()->initCountersGapsArray(); // Default is not created $created = false; // Is the file's header initialized? - if (!$this->getIteratorInstance()->isFileHeaderInitialized()) { + if (!$this->getIteratorInstance()->getBinaryFileInstance()->isFileHeaderInitialized()) { // First pre-allocate a bit /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...'); - $this->getIteratorInstance()->preAllocateFile('index'); + $this->getIteratorInstance()->getBinaryFileInstance()->preAllocateFile('index'); // Then write file header /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->createFileHeader() ...'); - $this->getIteratorInstance()->createFileHeader(); + $this->getIteratorInstance()->getBinaryFileInstance()->createFileHeader(); // Mark as freshly created $created = true; @@ -218,7 +222,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { if (!$created) { // Analyze file structure /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...'); - $this->getIteratorInstance()->analyzeFileStructure(); + $this->getIteratorInstance()->getBinaryFileInstance()->analyzeFileStructure(); } // Trace message @@ -256,7 +260,12 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { */ public function getFileSize () { // Call iterator's method - return $this->getIteratorInstance()->getFileSize(); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!'); + $fileSize = $this->getIteratorInstance()->getBinaryFileInstance()->getFileSize(); + + // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileSize=%d - EXIT!', $fileSize)); + return $fileSize; } /** @@ -276,8 +285,8 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); } - // Partial stub! - $this->partialStub('length=' . $length); + // Debug message + /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: length=%d,this=%s', __METHOD__, __LINE__, $length, print_r($this, true))); } /** @@ -302,7 +311,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // Call iterated object's method /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream)); - $status = $this->getIteratorInstance()->writeAtPosition($seekPosition, $dataStream); + $status = $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition($seekPosition, $dataStream); // Return status /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: status[%s]=%d - EXIT!', gettype($status), $status)); @@ -316,10 +325,10 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { */ public function isIndexLoaded () { // Is the file gaps-only? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!'); - if ($this->getIteratorInstance()->isFileGapsOnly()) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!'); + if ($this->getIteratorInstance()->getBinaryFileInstance()->isFileGapsOnly()) { // Then skip below code as this implies the file has been fully analyzed and "loaded" - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!'); return TRUE; } diff --git a/framework/main/classes/index/file/stack/class_FileStackIndex.php b/framework/main/classes/index/file/stack/class_FileStackIndex.php index 21d1e6a9..e74177ab 100644 --- a/framework/main/classes/index/file/stack/class_FileStackIndex.php +++ b/framework/main/classes/index/file/stack/class_FileStackIndex.php @@ -59,7 +59,7 @@ class FileStackIndex extends BaseFileIndex implements IndexableStack, Registerab $indexInstance = new FileStackIndex(); // Initialize index - $indexInstance->initIndex($fileInfoInstance); + $indexInstance->initFileIndex($fileInfoInstance); // Return the prepared instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString())); diff --git a/framework/main/classes/iterator/file/class_FileIterator.php b/framework/main/classes/iterator/file/class_FileIterator.php index f3352326..e820af7c 100644 --- a/framework/main/classes/iterator/file/class_FileIterator.php +++ b/framework/main/classes/iterator/file/class_FileIterator.php @@ -5,13 +5,13 @@ namespace Org\Mxchange\CoreFramework\Iterator\File; // Import framework stuff use Org\Mxchange\CoreFramework\Filesystem\File\BinaryFile; use Org\Mxchange\CoreFramework\Iterator\BaseIterator; -use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator; use Org\Mxchange\CoreFramework\Traits\File\BinaryFileTrait; // Import SPL stuff use \BadMethodCallException; use \InvalidArgumentException; use \OutOfBoundsException; +use \SeekableIterator; /** * A file iterator @@ -35,7 +35,7 @@ use \OutOfBoundsException; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FileIterator extends BaseIterator implements SeekableWritableFileIterator { +class FileIterator extends BaseIterator implements SeekableIterator { // Load traits use BinaryFileTrait; @@ -160,11 +160,10 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * Seeks to given position * * @param $seekPosition Seek position in file - * @param $whence Added to offset (default: only use offset to seek to) - * @return $status Status of this operation + * @return void * @throws OutOfBoundsException If the position is not seekable */ - public function seek (int $seekPosition, int $whence = SEEK_SET) { + public function seek (int $seekPosition) { // Validate parameter //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence)); if ($seekPosition < 0) { @@ -173,398 +172,10 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator } // Call file instance - $status = $this->getBinaryFileInstance()->seek($seekPosition, $whence); - - // Return status - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status))); - return $status; - } - - /** - * Size of file stack - * - * @return $size Size (in bytes) of file - */ - public function size () { - // Call the file object - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBinaryFileInstance()->size(); - - // Return size - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); - return $size; - } - - /** - * Reads given amount of bytes from file. - * - * @param $bytes Amount of bytes to read - * @return $data Data read from file - * @throws OutOfBoundsException If the position is not seekable - */ - public function read (int $bytes = 0) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: bytes=%d - CALLED!', $bytes)); - if ($bytes < 0) { - // Throw exception - throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes)); - } - - // Call file instance - $data = $this->getBinaryFileInstance()->read($bytes); - - // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data))); - return $data; - } - - /** - * Analyzes entries in index file. This will count all found (and valid) - * entries, mark invalid as damaged and count gaps ("fragmentation"). If - * only gaps are found, the file is considered as "virgin" (no entries). - * - * @return void - */ - public function analyzeFileStructure () { - // Just call the file instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBinaryFileInstance()->analyzeFileStructure(); - - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Checks whether the file header is initialized - * - * @return $isInitialized Whether the file header is initialized - */ - public function isFileHeaderInitialized () { - // Just call the file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $isInitialized = $this->getBinaryFileInstance()->isFileHeaderInitialized(); - - // Return flag - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isInitialized=%d - EXIT!', intval($isInitialized))); - return $isInitialized; - } - - /** - * Creates the assigned file - * - * @return void - */ - public function createFileHeader () { - // Just call the file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBinaryFileInstance()->createFileHeader(); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Pre-allocates file (if enabled) with some space for later faster write access. - * - * @param $type Type of the file - * @return void - * @throws InvalidArgumentException If a parameter is not valid - */ - public function preAllocateFile (string $type) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: type=%s - CALLED!', $type)); - if (empty($type)) { - // Throw IAE - throw new InvalidArgumentException('Parameter "type" is empty'); - } - - // Just call the file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->preAllocateFile(%s) ...', $type)); - $this->getBinaryFileInstance()->preAllocateFile($type); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Initializes counter for valid entries, arrays for damaged entries and - * an array for gap seek positions. If you call this method on your own, - * please re-analyze the file structure. So you are better to call - * analyzeFileStructure() instead of this method. - * - * @return void - */ - public function initCountersGapsArray () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBinaryFileInstance()->initCountersGapsArray(); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Getter for header size - * - * @return $totalEntries Size of file header - */ - public final function getHeaderSize () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBinaryFileInstance()->getHeaderSize(); - - // Return size - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); - return $size; - } - - /** - * Setter for header size - * - * @param $headerSize Size of file header - * @return void - */ - public final function setHeaderSize (int $headerSize) { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: headerSize=%d - CALLED!', $headerSize)); - $this->getBinaryFileInstance()->setHeaderSize($headerSize); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Getter for header array - * - * @return $header Header array - */ - public final function getHeader () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $header = $this->getBinaryFileInstance()->getHeader(); - - // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - EXIT!', count($header))); - return $header; - } - - /** - * Setter for header - * - * @param $header Array for a file header - * @return void - */ - public final function setHeader (array $header) { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - CALLED!', count($header))); - $this->getBinaryFileInstance()->setHeader($header); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Updates seekPosition attribute from file to avoid to much access on file. - * - * @return void - */ - public function updateSeekPosition () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBinaryFileInstance()->updateSeekPosition(); - - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); - } - - /** - * Getter for total entries - * - * @return $totalEntries Total entries in this file - */ - public final function getCounter () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $counter = $this->getBinaryFileInstance()->getCounter(); - - // Return counter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: counter=%d - EXIT!', $counter)); - return $counter; - } - - /** - * "Getter" for file size - * - * @return $fileSize Size of currently loaded file - */ - public function getFileSize () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBinaryFileInstance()->getFileSize(); - - // Return size - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); - return $size; - } - - /** - * Writes data at given position - * - * @param $seekPosition Seek position - * @param $data Data to be written - * @param $flushHeader Whether to flush the header (default: flush) - * @return void - * @throws OutOfBoundsException If the position is not seekable - * @throws InvalidArgumentException If a parameter is not valid - */ - public function writeData (int $seekPosition, string $data, bool $flushHeader = true) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,data(%d)=%s,flushHeader=%d - CALLED!', $seekPosition, strlen($data), $data, intval($flushHeader))); - if ($seekPosition < 0) { - // Throw exception - throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition)); - } elseif (empty($data)) { - // Throw IAE - throw new InvalidArgumentException('Parameter "data" is empty'); - } - - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->writeData(%d,data()=%d,%d) ...', $seekPosition, strlen($data), intval($flushHeader))); - $this->getBinaryFileInstance()->writeData($seekPosition, $data, $flushHeader); + $this->getBinaryFileInstance()->seek($seekPosition); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); } - /** - * Writes at given position by seeking to it. - * - * @param $seekPosition Seek position in file - * @param $dataStream Data to be written - * @return mixed Number of writes bytes or false on error - * @throws OutOfBoundsException If the position is not seekable - * @throws InvalidArgumentException If a parameter is not valid - */ - public function writeAtPosition (int $seekPosition, string $dataStream) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: 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)); - } elseif (empty($dataStream)) { - // Empty dataStream - throw new InvalidArgumentException('Parameter "dataStream" is empty'); - } - - // Call iterated object's method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream)); - $status = $this->getBinaryFileInstance()->writeAtPosition($seekPosition, $dataStream); - - // Return status - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status[%s]=%d - EXIT!', gettype($status), $status)); - return $status; - } - - /** - * Getter for seek position - * - * @return $seekPosition Current seek position (stored here in object) - */ - public function getSeekPosition () { - // Call file instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $seekPosition = $this->getBinaryFileInstance()->getSeekPosition(); - - // Return position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition)); - return $seekPosition; - } - - /** - * Writes given value to the file and returns a hash and gap position for it - * - * @param $stackName Group identifier - * @param $value Value to be added to the stack - * @return $data Hash and gap position - * @throws InvalidArgumentException If a parameter is not valid - */ - public function writeValueToFile (string $stackName, $value) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value))); - if (empty($stackName)) { - // Throw IAE - throw new InvalidArgumentException('Parameter "stackName" is empty'); - } elseif (is_resource($value) || is_object($value)) { - // Resources and objects are nothing for file-based indexes (mostly) - throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value))); - } - - // Call file instance - $data = $this->getBinaryFileInstance()->writeValueToFile($stackName, $value); - - // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data))); - return $data; - } - - /** - * Writes given raw data to the file and returns a gap position and length - * - * @param $stackName Group identifier - * @param $hash Hash from encoded value - * @param $encoded Encoded value to be written to the file - * @return $data Gap position and length of the raw data - */ - public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,hash=%s,encoded(%d)=%s - CALLED!', $stackName, $hash, strlen($encoded), $encoded)); - - // Call file instance - $data = $this->getBinaryFileInstance()->writeDataToFreeGap($stackName, $hash, $encoded); - - // Return data - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data))); - return $data; - } - - /** - * Searches for next suitable gap the given length of data can fit in - * including padding bytes. - * - * @param $length Length of raw data - * @return $seekPosition Found next gap's seek position - * @throws InvalidArgumentException If a parameter is invalid - */ - public function searchNextGap (int $length) { - // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: length=%d - CALLED!', $length)); - if ($length <= 0) { - // Throw IAE - throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); - } - - // Call file instance - $seekPosition = $this->getBinaryFileInstance()->searchNextGap($length); - - // Return position - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition)); - return $seekPosition; - } - - /** - * Checks whether the abstracted file only contains gaps by counting all - * gaps' bytes together and compare it to total length. - * - * @return $isGapsOnly Whether the abstracted file only contains gaps - */ - public function isFileGapsOnly () { - // Call file instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $isGapsOnly = $this->getBinaryFileInstance()->isFileGapsOnly(); - - // Return position - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isGapsOnly=%d - EXIT!', $isGapsOnly)); - return $isGapsOnly; - } - } diff --git a/framework/main/classes/resolver/command/class_BaseCommandResolver.php b/framework/main/classes/resolver/command/class_BaseCommandResolver.php index dc6ba713..c18046bf 100644 --- a/framework/main/classes/resolver/command/class_BaseCommandResolver.php +++ b/framework/main/classes/resolver/command/class_BaseCommandResolver.php @@ -81,7 +81,7 @@ abstract class BaseCommandResolver extends BaseResolver { * @throws InvalidCommandException Thrown if even the default * command class is missing (bad!) */ - protected function loadCommand ($commandName) { + protected function loadCommand (string $commandName) { // Init command instance $commandInstance = NULL; diff --git a/framework/main/classes/resolver/controller/class_BaseControllerResolver.php b/framework/main/classes/resolver/controller/class_BaseControllerResolver.php index b2f4e7c0..2d3669aa 100644 --- a/framework/main/classes/resolver/controller/class_BaseControllerResolver.php +++ b/framework/main/classes/resolver/controller/class_BaseControllerResolver.php @@ -116,13 +116,13 @@ abstract class BaseControllerResolver extends BaseResolver { // No news at main controller or non-news controller $this->setClassName($className); } - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName()); // Is this class loaded? + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName()); if (!class_exists($this->getClassName())) { // Throw an exception here throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); - } // END - if + } // Try to read a config entry for our resolver including controller name... ;-) $resolverConfigEntry = sprintf('%s_cmd_%s_resolver_class', strtolower($this->getClassPrefix()), strtolower($controllerName)); @@ -159,7 +159,7 @@ abstract class BaseControllerResolver extends BaseResolver { * @throws InvalidArgumentException Thrown if given controller is not set * @throws DefaultControllerException Thrown if default controller was not found */ - protected function isControllerValid ($namespace, $controllerName) { + protected function isControllerValid (string $namespace, string $controllerName) { // Is a action set? if (empty($namespace)) { // Then thrown an exception here @@ -174,16 +174,19 @@ abstract class BaseControllerResolver extends BaseResolver { // Create class name $className = sprintf( - '%s\%sController', + '%s\%s%sController', $namespace, - $this->getCapitalizedClassPrefix() . StringUtils::convertToClassName($controllerName) + $this->getCapitalizedClassPrefix(), + StringUtils::convertToClassName($controllerName) ); + // Application's default news controller $appDefaultControllerName = sprintf( '%s\%sDefaultNewsController', $namespace, $this->getCapitalizedClassPrefix() ); + // Framework's default news controller $defaultControllerName = sprintf( 'Org\Mxchange\CoreFramework\Controller\News\%sDefaultNewsController', diff --git a/framework/main/classes/resolver/controller/console/class_ConsoleControllerResolver.php b/framework/main/classes/resolver/controller/console/class_ConsoleControllerResolver.php index d88c45d6..dc2ee291 100644 --- a/framework/main/classes/resolver/controller/console/class_ConsoleControllerResolver.php +++ b/framework/main/classes/resolver/controller/console/class_ConsoleControllerResolver.php @@ -56,7 +56,7 @@ class ConsoleControllerResolver extends BaseControllerResolver implements Contro * @throws InvalidArgumentException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createConsoleControllerResolver ($namespace, $controllerName) { + public static final function createConsoleControllerResolver (string $namespace, string $controllerName) { // Create the new instance $resolverInstance = new ConsoleControllerResolver(); diff --git a/framework/main/classes/resolver/controller/html/class_HtmlControllerResolver.php b/framework/main/classes/resolver/controller/html/class_HtmlControllerResolver.php index b1237daf..4d164176 100644 --- a/framework/main/classes/resolver/controller/html/class_HtmlControllerResolver.php +++ b/framework/main/classes/resolver/controller/html/class_HtmlControllerResolver.php @@ -56,7 +56,7 @@ class HtmlControllerResolver extends BaseControllerResolver implements Controlle * @throws InvalidArgumentException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createHtmlControllerResolver ($namespace, $controllerName) { + public static final function createHtmlControllerResolver (string $namespace, string $controllerName) { // Create the new instance $resolverInstance = new HtmlControllerResolver(); diff --git a/framework/main/classes/resolver/controller/image/class_ImageControllerResolver.php b/framework/main/classes/resolver/controller/image/class_ImageControllerResolver.php index 6201a284..9fead583 100644 --- a/framework/main/classes/resolver/controller/image/class_ImageControllerResolver.php +++ b/framework/main/classes/resolver/controller/image/class_ImageControllerResolver.php @@ -56,7 +56,7 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll * @throws InvalidArgumentException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createImageControllerResolver ($namespace, $controllerName) { + public static final function createImageControllerResolver (string $namespace, string $controllerName) { // Create the new instance $resolverInstance = new ImageControllerResolver(); diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index 7e09a36d..3eaa1f1d 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -7,7 +7,6 @@ use Org\Mxchange\CoreFramework\Factory\Stack\File\FileStackIndexFactory; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; -use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator; use Org\Mxchange\CoreFramework\Stack\BaseStacker; use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait; use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait; diff --git a/framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php b/framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php deleted file mode 100644 index 5c3b67cc..00000000 --- a/framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php +++ /dev/null @@ -1,201 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -interface SeekableWritableFileIterator extends SeekableIterator { - /** - * Size of file stack - * - * @return $size Size (in bytes) of file - */ - function size (); - - /** - * Reads given amount of bytes from file. - * - * @param $bytes Amount of bytes to read - * @return $data Data read from file - */ - function read (int $bytes = 0); - - /** - * Analyzes entries in index file. This will count all found (and valid) - * entries, mark invalid as damaged and count gaps ("fragmentation"). If - * only gaps are found, the file is considered as "virgin" (no entries). - * - * @return void - */ - function analyzeFileStructure (); - - /** - * Checks whether the file header is initialized - * - * @return $isInitialized Whether the file header is initialized - */ - function isFileHeaderInitialized (); - - /** - * Creates the assigned file - * - * @return void - */ - function createFileHeader (); - - /** - * Pre-allocates file (if enabled) with some space for later faster write access. - * - * @param $type Type of the file - * @return void - */ - function preAllocateFile (string $type); - - /** - * Initializes counter for valid entries, arrays for damaged entries and - * an array for gap seek positions. If you call this method on your own, - * please re-analyze the file structure. So you are better to call - * analyzeFileStructure() instead of this method. - * - * @return void - */ - function initCountersGapsArray (); - - /** - * Getter for header size - * - * @return $totalEntries Size of file header - */ - function getHeaderSize (); - - /** - * Setter for header size - * - * @param $headerSize Size of file header - * @return void - */ - function setHeaderSize (int $headerSize); - - /** - * Getter for header array - * - * @return $totalEntries Size of file header - */ - function getHeader (); - - /** - * Setter for header - * - * @param $header Array for a file header - * @return void - */ - function setHeader (array $header); - - /** - * Updates seekPosition attribute from file to avoid to much access on file. - * - * @return void - */ - function updateSeekPosition (); - - /** - * Getter for total entries - * - * @return $totalEntries Total entries in this file - */ - function getCounter (); - - /** - * "Getter" for file size - * - * @return $fileSize Size of currently loaded file - */ - function getFileSize (); - - /** - * Getter for seek position - * - * @return $seekPosition Current seek position (stored here in object) - */ - function getSeekPosition (); - - /** - * Searches for next suitable gap the given length of data can fit in - * including padding bytes. - * - * @param $length Length of raw data - * @return $seekPosition Found next gap's seek position - */ - function searchNextGap (int $length); - - /** - * Checks whether the abstracted file only contains gaps by counting all - * gaps' bytes together and compare it to total length. - * - * @return $isGapsOnly Whether the abstracted file only contains gaps - */ - function isFileGapsOnly(); - - /** - * Writes data at given position - * - * @param $seekPosition Seek position - * @param $data Data to be written - * @param $flushHeader Whether to flush the header (default: flush) - * @return void - */ - function writeData (int $seekPosition, string $data, bool $flushHeader = true); - - /** - * Writes at given position by seeking to it. - * - * @param $seekPosition Seek position in file - * @param $data Data to be written - * @return mixed Number of writes bytes or false on error - */ - function writeAtPosition (int $seedPosition, string $data); - - /** - * Writes given value to the file and returns a hash and gap position for it - * - * @param $groupId Group identifier - * @param $value Value to be added to the stack - * @return $data Hash and gap position - */ - function writeValueToFile (string $groupId, $value); - - /** - * Writes given raw data to the file and returns a gap position and length - * - * @param $groupId Group identifier - * @param $hash Hash from encoded value - * @param $encoded Encoded value to be written to the file - * @return $data Gap position and length of the raw data - */ - function writeDataToFreeGap (string $groupId, string $hash, string $encoded); - -} -- 2.39.5