From: Roland Häder Date: Wed, 9 Dec 2020 05:40:21 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=024347bb5d62151f49c959cdeeaecc061fb2be66;p=core.git Continued: - interface Block was abused for file classes (index file/file-based stack) and is now free of it - BinaryFile replaces it and other inheriting interfaces are cleared (moved methods to BinaryFile) Signed-off-by: Roland Häder --- diff --git a/framework/main/classes/actions/class_ b/framework/main/classes/actions/class_ index d4f9866f..9a53fd96 100644 --- a/framework/main/classes/actions/class_ +++ b/framework/main/classes/actions/class_ @@ -1,6 +1,6 @@ getInstance($type . '_index'); } else { // Get the handler instance - $indexInstance = ObjectFactory::createObjectByConfiguredName($type . '_file_stack_index_class', array($infoInstance)); + $indexInstance = ObjectFactory::createObjectByConfiguredName($type . '_file_stack_index_class', [$fileInfoInstance]); // Add it to the registry GenericRegistry::getRegistry()->addInstance($type . '_index', $indexInstance); diff --git a/framework/main/classes/feature/class_ b/framework/main/classes/feature/class_ index 49f5f862..febb25f8 100644 --- a/framework/main/classes/feature/class_ +++ b/framework/main/classes/feature/class_ @@ -1,6 +1,6 @@ . */ -abstract class BaseBinaryFile extends BaseAbstractFile { +abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { + // Load traits + use StackableTrait; + use IndexableStackTrait; + /** * Separator for header data */ @@ -135,11 +144,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile { */ private $currentBlock = ''; - /** - * An instance of a Block class - */ - private $blockInstance = NULL; - /** * Protected constructor * @@ -154,25 +158,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile { $this->initCountersGapsArray(); } - /** - * Setter for Block instance - * - * @param $blockInstance An instance of an Block class - * @return void - */ - protected final function setBlockInstance (Block $blockInstance) { - $this->blockInstance = $blockInstance; - } - - /** - * Getter for Block instance - * - * @return $blockInstance An instance of an Block class - */ - public final function getBlockInstance () { - return $this->blockInstance; - } - /** * Setter for backBuffer field * @@ -695,7 +680,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile { self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...'); // Calculate minimum length for one entry and get file size - $minimumBlockLength = $this->getBlockInstance()->calculateMinimumBlockLength(); + $minimumBlockLength = $this->getIndexableStackInstance()->calculateMinimumBlockLength(); $fileSize = $this->getFileSize(); // Calulcate seek position @@ -902,7 +887,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile { // First calculate minimum block length //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition())); - $length = $this->getBlockInstance()->calculateMinimumBlockLength(); + $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength(); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length)); // Read possibly back-buffered bytes from previous call of next(). @@ -980,7 +965,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile { public function isValid () { // First calculate minimum block length //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); - $length = $this->getBlockInstance()->calculateMinimumBlockLength(); + $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength(); // Short be more than zero! //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length)); @@ -1023,11 +1008,23 @@ abstract class BaseBinaryFile extends BaseAbstractFile { * Reads the file header * * @return void + * @throws LogicException If both instances are not set */ public function readFileHeader () { - // Call block instance + // Is index set or stack? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); - $this->getBlockInstance()->readFileHeader(); + if ($this->getIndexableStackInstance() instanceof IndexableStack) { + // Call index instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexableStackInstance->readFileHeader() ...'); + $this->getIndexableStackInstance()->readFileHeader(); + } elseif ($this->getStackInstance() instanceof StackableFile) { + // Call stacke instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readFileHeader() ...'); + $this->getStackInstance()->readFileHeader(); + } else { + // Bad logic? + throw new LogicException('Wether indexableStackInstance nor stackableFileInstance are set'); + } // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); @@ -1041,7 +1038,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile { public function flushFileHeader () { // Call block instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!'); - $this->getBlockInstance()->flushFileHeader(); + $this->getIndexableStackInstance()->flushFileHeader(); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!'); 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 c485275f..01092713 100644 --- a/framework/main/classes/file_directories/binary/index/class_IndexFile.php +++ b/framework/main/classes/file_directories/binary/index/class_IndexFile.php @@ -3,9 +3,10 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Index; // Import framework stuff -use Org\Mxchange\CoreFramework\Filesystem\Block; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; +use Org\Mxchange\CoreFramework\Filesystem\Index\IndexableFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; +use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack; // Import SPL stuff use \SplFileInfo; @@ -32,7 +33,7 @@ use \SplFileInfo; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class IndexFile extends BaseBinaryFile implements Block { +class IndexFile extends BaseBinaryFile implements IndexableFile { /** * Protected constructor * @@ -47,26 +48,26 @@ class IndexFile extends BaseBinaryFile implements Block { * Creates an instance of this File class and prepares it for usage * * @param $fileInfoInstance An instance of a SplFileInfo class - * @param $blockInstance An instance of a Block class - * @return $fileInstance An instance of this File class + * @param $indexInstance An instance of a IndexableStack class + * @return $indexFileInstance An instance of an IndexableFile class */ - public final static function createIndexFile (SplFileInfo $fileInfoInstance, Block $blockInstance) { + public final static function createIndexFile (SplFileInfo $fileInfoInstance, IndexableStack $indexInstance) { // Get a new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,blockInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $blockInstance->__toString())); - $fileInstance = new IndexFile(); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,indexInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $indexInstance->__toString())); + $indexFileInstance = new IndexFile(); - // Set block instance here for callbacks - $fileInstance->setBlockInstance($blockInstance); + // Set file instance here for callbacks + $indexFileInstance->setIndexableStackInstance($indexInstance); // Expand file name with .idx $indexInfoInstance = new SplFileInfo(sprintf('%s.idx', $fileInfoInstance->__toString())); // Init this abstract file - $fileInstance->initFile($indexInfoInstance); + $indexFileInstance->initFile($indexInfoInstance); // Return the prepared instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInstance=%s - EXIT!', $fileInstance->__toString())); - return $fileInstance; + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: indexFileInstance=%s - EXIT!', $indexFileInstance->__toString())); + return $indexFileInstance; } /** 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 86c800a2..2cd5dde0 100644 --- a/framework/main/classes/file_directories/binary/stack/class_StackFile.php +++ b/framework/main/classes/file_directories/binary/stack/class_StackFile.php @@ -3,12 +3,14 @@ namespace Org\Mxchange\CoreFramework\Stack\File; // Import framework stuff -use Org\Mxchange\CoreFramework\Filesystem\Block; +use Org\Mxchange\CoreFramework\Filesystem\Stack\FileStacker; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; +use Org\Mxchange\CoreFramework\Stack\File\StackableFile; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; // Import SPL stuff +use \InvalidArgumentException; use \SplFileInfo; /** @@ -33,7 +35,7 @@ use \SplFileInfo; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class StackFile extends BaseBinaryFile implements Block { +class StackFile extends BaseBinaryFile implements FileStacker { /** * Protected constructor * @@ -48,20 +50,22 @@ class StackFile extends BaseBinaryFile implements Block { * Creates an instance of this File class and prepares it for usage * * @param $infoInstance An instance of a SplFileInfo class - * @param $blockInstance An instance of a Block class + * @param $stackInstance An instance of a StackableFile class * @return $fileInstance An instance of this File class */ - public final static function createStackFile (SplFileInfo $infoInstance, Block $blockInstance) { + 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())); $fileInstance = new StackFile(); - // Set block instance here for callbacks - $fileInstance->setBlockInstance($blockInstance); + // Set stack instance here for callbacks + $fileInstance->setStackInstance($stackInstance); // Init this abstract file $fileInstance->initFile($infoInstance); // Return the prepared instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: fileInstance=%s - EXIT!', $fileInstance->__toString())); return $fileInstance; } @@ -71,11 +75,18 @@ class StackFile extends BaseBinaryFile implements Block { * @param $groupId Group identifier * @param $value Value to be added to the stack * @return $data Hash and gap position + * @throws InvalidArgumentException If a parameter is not valid */ - public function writeValueToFile ($groupId, $value) { - // Make sure no objects/resources are added as the serialization may fail - assert(!is_object($value)); - assert(!is_resource($value)); + public function writeValueToFile (string $groupId, $value) { + // Validate parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value))); + if (empty($groupId)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "groupId" is empty'); + } elseif (is_object($value) || is_resource($value)) { + // Not wanted here + throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value))); + } // Encode/convert the value into a "binary format" $encoded = StringUtils::encodeData($value); @@ -84,7 +95,7 @@ class StackFile extends BaseBinaryFile implements Block { $hash = self::hash($encoded); // Then write it to the next free gap - $data = $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded); + $data = $this->getStackInstance()->writeDataToFreeGap($groupId, $hash, $encoded); // Return info return $data; diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index 32df15b5..c1c71662 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -1,6 +1,6 @@ initIndex($fileName); + $indexInstance->initIndex($fileInfoInstance); // Return the prepared instance return $indexInstance; diff --git a/framework/main/classes/index/class_BaseIndex.php b/framework/main/classes/index/class_BaseIndex.php index 79e1c054..5e56d1dc 100644 --- a/framework/main/classes/index/class_BaseIndex.php +++ b/framework/main/classes/index/class_BaseIndex.php @@ -37,7 +37,7 @@ use \UnexpectedValueException; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -abstract class BaseIndex extends BaseFrameworkSystem { +abstract class BaseIndex extends BaseFrameworkSystem implements Indexable { // Load traits use IteratorTrait; @@ -174,7 +174,7 @@ abstract class BaseIndex extends BaseFrameworkSystem { $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this)); // Get iterator instance - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance)); + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', [$fileInstance]); // Set iterator here $this->setIteratorInstance($iteratorInstance); @@ -219,7 +219,7 @@ abstract class BaseIndex extends BaseFrameworkSystem { // Freshly created? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: created=%d', intval($created))); if (!$created) { - // Count all entries in file + // Analyze file structure /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...'); $this->getIteratorInstance()->analyzeFileStructure(); } diff --git a/framework/main/classes/index/file_stack/class_FileStackIndex.php b/framework/main/classes/index/file_stack/class_FileStackIndex.php index 0d169246..570cc8fd 100644 --- a/framework/main/classes/index/file_stack/class_FileStackIndex.php +++ b/framework/main/classes/index/file_stack/class_FileStackIndex.php @@ -7,7 +7,7 @@ use Org\Mxchange\CoreFramework\Index\BaseIndex; use Org\Mxchange\CoreFramework\Index\Indexable; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Stack\File\StackableFile; -use Org\Mxchange\CoreFramework\Stack\Index\IndexableStack; +use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack; // Import SPL stuff use \InvalidArgumentException; @@ -67,16 +67,35 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable { } /** - * Adds given hash to an index file + * Adds given data's hash to an index file * * @param $groupId Name of stack to add hash for * @param $data Hash and gap position to be added to the index * @return void + * @throws InvalidArgumentException If a parameter is not valid * @throws UnexpectedValueException If an invalid gap position is being returned */ - public function addHashToIndex (string $groupId, array $data) { + public function addHashedDataToIndex (string $groupId, array $data) { + // Validate parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,data()=%d - CALLED!', $groupId, count($data))); + if (empty($groupId)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "groupId" is empty'); + } elseif (count($data) == 0) { + // Throw it again + throw new InvalidArgumentException('Parameter "data" is an empty array'); + } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) { + // Important array element missing + throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH])); + } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) { + // Important array element missing + throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION])); + } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) { + // Important array element missing + throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH])); + } + // Raw data been written to the file - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', $groupId, $data[StackableFile::ARRAY_NAME_HASH], $data[StackableFile::ARRAY_NAME_GAP_POSITION], $data[StackableFile::ARRAY_NAME_DATA_LENGTH])); $rawData = sprintf('%s%s%s%s%s%s%s', $groupId, Indexable::SEPARATOR_GROUP_HASH, @@ -122,6 +141,9 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable { // Throw IAE throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); } + + // Partial stub! + $this->partialStub('length=' . $length); } /** @@ -152,4 +174,15 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable { return $status; } + /** + * Checks if this index file has been fully and properly loaded. + * + * @return $isLoaded Whether this index file has been loaded + */ + public function isIndexFileLoaded () { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-STACK-INDEX: CALLED!'); + /* DEBUG-DIE: */ die(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true))); + } + } diff --git a/framework/main/classes/iterator/class_ b/framework/main/classes/iterator/class_ index d15b26e9..1c99c2d7 100644 --- a/framework/main/classes/iterator/class_ +++ b/framework/main/classes/iterator/class_ @@ -1,6 +1,6 @@ . */ class FileIterator extends BaseIterator implements SeekableWritableFileIterator { - /** - * An instance of a Block class - */ - private $blockInstance = NULL; + // Load traits + use BinaryFileTrait; /** * Protected constructor @@ -52,41 +51,22 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator /** * Creates an instance of this class * - * @param $blockInstance An instance of a Block class + * @param $binaryFileInstance An instance of a BinaryFile class * @return $iteratorInstance An instance of a Iterator class */ - public final static function createFileIterator (Block $blockInstance) { + public final static function createFileIterator (BinaryFile $binaryFileInstance) { // Get new instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: blockInstance=%s - CALLED!', $blockInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: binaryFileInstance=%s - CALLED!', $binaryFileInstance->__toString())); $iteratorInstance = new FileIterator(); // Set the instance here - $iteratorInstance->setBlockInstance($blockInstance); + $iteratorInstance->setBinaryFileInstance($binaryFileInstance); // Return the prepared instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: iteratorInstance=%s - EXIT!', $iteratorInstance->__toString())); return $iteratorInstance; } - /** - * Setter for Block instance - * - * @param $blockInstance An instance of an Block class - * @return void - */ - protected final function setBlockInstance (Block $blockInstance) { - $this->blockInstance = $blockInstance; - } - - /** - * Getter for Block instance - * - * @return $blockInstance An instance of an Block class - */ - public final function getBlockInstance () { - return $this->blockInstance; - } - /** * Gets currently read data * @@ -101,8 +81,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?'); } - // Call block instance - $current = $this->getBlockInstance()->current(); + // Call file instance + $current = $this->getBinaryFileInstance()->current(); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: current[]=%s - EXIT!', gettype($current))); @@ -123,8 +103,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?'); } - // Get key from block instance - $key = $this->getBlockInstance()->determineSeekPosition(); + // Get key from file instance + $key = $this->getBinaryFileInstance()->determineSeekPosition(); // Return key //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: key[%s]=%s - EXIT!', gettype($key), $key)); @@ -132,14 +112,14 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator } /** - * Advances to next "block" of bytes + * Advances to next "file" of bytes * * @return void */ public function next () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->next(); + $this->getBinaryFileInstance()->next(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -151,9 +131,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $status Status of this operation */ public function rewind () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->rewind(); + $this->getBinaryFileInstance()->rewind(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -166,9 +146,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $isValid Whether the next entry is valid */ public function valid () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $isValid = $this->getBlockInstance()->valid(); + $isValid = $this->getBinaryFileInstance()->valid(); // Return flag //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isValid=%d - EXIT!', intval($isValid))); @@ -191,8 +171,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition)); } - // Call block instance - $status = $this->getBlockInstance()->seek($seekPosition, $whence); + // 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))); @@ -205,9 +185,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $size Size (in bytes) of file */ public function size () { - // Call the block object + // Call the file object //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBlockInstance()->size(); + $size = $this->getBinaryFileInstance()->size(); // Return size //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); @@ -228,8 +208,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes)); } - // Call block instance - $data = $this->getBlockInstance()->read($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))); @@ -244,9 +224,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public function analyzeFileStructure () { - // Just call the block instance + // Just call the file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->analyzeFileStructure(); + $this->getBinaryFileInstance()->analyzeFileStructure(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -258,9 +238,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $isInitialized Whether the file header is initialized */ public function isFileHeaderInitialized () { - // Just call the block instance + // Just call the file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $isInitialized = $this->getBlockInstance()->isFileHeaderInitialized(); + $isInitialized = $this->getBinaryFileInstance()->isFileHeaderInitialized(); // Return flag //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isInitialized=%d - EXIT!', intval($isInitialized))); @@ -273,9 +253,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public function createFileHeader () { - // Just call the block instance + // Just call the file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->createFileHeader(); + $this->getBinaryFileInstance()->createFileHeader(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -296,8 +276,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException('Parameter "type" is empty'); } - // Just call the block instance - $this->getBlockInstance()->preAllocateFile($type); + // Just call the file instance + $this->getBinaryFileInstance()->preAllocateFile($type); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -312,9 +292,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public function initCountersGapsArray () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->initCountersGapsArray(); + $this->getBinaryFileInstance()->initCountersGapsArray(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -326,9 +306,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $totalEntries Size of file header */ public final function getHeaderSize () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBlockInstance()->getHeaderSize(); + $size = $this->getBinaryFileInstance()->getHeaderSize(); // Return size //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); @@ -342,9 +322,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public final function setHeaderSize (int $headerSize) { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: headerSize=%d - CALLED!', $headerSize)); - $this->getBlockInstance()->setHeaderSize($headerSize); + $this->getBinaryFileInstance()->setHeaderSize($headerSize); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -356,9 +336,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $header Header array */ public final function getHeader () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $header = $this->getBlockInstance()->getHeader(); + $header = $this->getBinaryFileInstance()->getHeader(); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - EXIT!', count($header))); @@ -372,9 +352,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public final function setHeader (array $header) { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - CALLED!', count($header))); - $this->getBlockInstance()->setHeader($header); + $this->getBinaryFileInstance()->setHeader($header); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -386,9 +366,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return void */ public function updateSeekPosition () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $this->getBlockInstance()->updateSeekPosition(); + $this->getBinaryFileInstance()->updateSeekPosition(); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -400,9 +380,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $totalEntries Total entries in this file */ public final function getCounter () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $counter = $this->getBlockInstance()->getCounter(); + $counter = $this->getBinaryFileInstance()->getCounter(); // Return counter //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: counter=%d - EXIT!', $counter)); @@ -415,9 +395,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $fileSize Size of currently loaded file */ public function getFileSize () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $size = $this->getBlockInstance()->getFileSize(); + $size = $this->getBinaryFileInstance()->getFileSize(); // Return size //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size)); @@ -444,9 +424,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException('Parameter "data" is empty'); } - // Call block instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeData(%d,data()=%d,%d) ...', $seekPosition, strlen($data), intval($flushHeader))); - $this->getBlockInstance()->writeData($seekPosition, $data, $flushHeader); + // 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); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!'); @@ -472,8 +452,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator } // Call iterated object's method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream)); - $status = $this->getBlockInstance()->writeAtPosition($seekPosition, $dataStream); + //* 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)); @@ -486,9 +466,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @return $seekPosition Current seek position (stored here in object) */ public function getSeekPosition () { - // Call block instance + // Call file instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!'); - $seekPosition = $this->getBlockInstance()->getSeekPosition(); + $seekPosition = $this->getBinaryFileInstance()->getSeekPosition(); // Return position //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition)); @@ -514,8 +494,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value))); } - // Call block instance - $data = $this->getBlockInstance()->writeValueToFile($groupId, $value); + // Call file instance + $data = $this->getBinaryFileInstance()->writeValueToFile($groupId, $value); // Return data //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data))); @@ -532,10 +512,10 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator */ public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) { // Validate parameter - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded(%d)=%s - CALLED!', $groupId, $hash, strlen($encoded), $encoded)); - // Call block instance - $data = $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded); + // Call file instance + $data = $this->getBinaryFileInstance()->writeDataToFreeGap($groupId, $hash, $encoded); // Return data //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data))); @@ -558,8 +538,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator throw new InvalidArgumentException(sprintf('length=%d is not valid', $length)); } - // Call block instance - $seekPosition = $this->getBlockInstance()->searchNextGap($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)); diff --git a/framework/main/classes/mailer/class_ b/framework/main/classes/mailer/class_ index 7412028a..37ffef16 100644 --- a/framework/main/classes/mailer/class_ +++ b/framework/main/classes/mailer/class_ @@ -1,6 +1,6 @@ . */ -abstract class BaseFileStack extends BaseStacker implements StackableFile { +abstract class BaseFileStack extends BaseStacker { // Load traits use IndexableTrait; use IteratorTrait; @@ -244,9 +242,6 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->initCountersGapsArray() ...'); $this->getIteratorInstance()->initCountersGapsArray(); - // Default is not created/already exists - $created = false; - // Is the file's header initialized? if (!$this->getIteratorInstance()->isFileHeaderInitialized()) { // First pre-allocate a bit @@ -256,33 +251,39 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { // Then create file header /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: this->iteratorInstance->createFileHeader() ...'); $this->getIteratorInstance()->createFileHeader(); - - // Set flag - $created = true; } // Load the file header /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readFileHeader() ...'); $this->readFileHeader(); - // Not created/already exists? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: created=%d', intval($created))); - if (!$created) { - // Count all entries in file - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFileStructure() ...'); - $this->getIteratorInstance()->analyzeFileStructure(); - } - /* * Get stack index instance. This can be used for faster * "defragmentation" and startup. */ - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance[%s]=%s,type=%s', get_class($fileInfoInstance), $fileInfoInstance, $type)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Creating index instance for fileInfoInstance[%s]=%s,type=%s ...', get_class($fileInfoInstance), $fileInfoInstance, $type)); $indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileInfoInstance, $type); // And set it here + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: indexInstance=%s', $indexInstance->__toString())); $this->setIndexInstance($indexInstance); + // Is the index loaded correctly and the stack file is just created? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexFileLoaded() ...'); + if (!$this->getIndexInstance()->isIndexFileLoaded()) { + /* + * Something horrible has happened to the index as it should be + * loaded at this point. The stack's file structure then needs to + * be analyzed and the index rebuild. + */ + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFileStructure() ...'); + $this->getIteratorInstance()->analyzeFileStructure(); + + // Rebuild index from file + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->iteratorInstance->rebuildIndexFromStack(%s) ...', $this->__toString())); + $this->getIndexInstance()->rebuildIndexFromStack($this); + } + // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!'); } @@ -299,7 +300,8 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { */ protected function addValueToStack (string $stackerName, $value) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[%s]=%s - CALLED!', $stackerName, gettype($value), print_r($value, true))); + /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value))); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[%s]=%s', $stackerName, gettype($value), print_r($value, true))); if (empty($stackerName)) { // No empty stack name throw new InvalidArgumentException('Parameter "stackerName" is empty'); @@ -318,7 +320,9 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { $data = $this->getIteratorInstance()->writeValueToFile($stackerName, $value); // Add the hash and gap position to the index - $this->getIndexInstance()->addHashToIndex($stackerName, $data); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: data=%s', print_r($data, true)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->indexInstance->addHashedDataToIndex(%s,data()=%d) ...', $stackerName, count($data))); + $this->getIndexInstance()->addHashedDataToIndex($stackerName, $data); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!'); @@ -476,28 +480,6 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile { return $isEmpty; } - /** - * Initializes given stacker - * - * @param $stackerName Name of the stack - * @param $forceReInit Force re-initialization - * @return void - * @throws UnsupportedOperationException This method is not (and maybe never will be) supported - */ - public function initStack (string $stackerName, bool $forceReInit = false) { - throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Initializes all stacks - * - * @return void - * @throws UnsupportedOperationException This method is not (and maybe never will be) supported - */ - public function initStacks (array $stacks, bool $forceReInit = false) { - throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION); - } - /** * Checks whether the given stack is initialized (set in array $stackers) * diff --git a/framework/main/classes/streams/class_ b/framework/main/classes/streams/class_ index da201e4d..6400b38a 100644 --- a/framework/main/classes/streams/class_ +++ b/framework/main/classes/streams/class_ @@ -1,6 +1,6 @@ . */ interface Block extends FrameworkInterface { - /** - * Reads the file header - * - * @return void - */ - function readFileHeader (); - - /** - * Flushes the file header - * - * @return void - */ - function flushFileHeader (); - - /** - * Determines whether the EOF has been reached - * - * @return $isEndOfFileReached Whether the EOF has been reached - */ - function isEndOfFileReached (); - - /** - * 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 (); - - /** - * 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, string $rawData); - - /** - * 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); - - /** - * 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 $dataStream Data to be written - * @return mixed Number of writes bytes or false on error - * @throws InvalidArgumentException If a parameter is not valid - */ - function writeAtPosition (int $seekPosition, string $dataStream); - - /** - * 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); } diff --git a/framework/main/interfaces/class_ b/framework/main/interfaces/class_ index 241c8ced..d3a90f58 100644 --- a/framework/main/interfaces/class_ +++ b/framework/main/interfaces/class_ @@ -1,6 +1,6 @@ + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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 BinaryFile extends Filesystem { + /** + * Reads the file header + * + * @return void + */ + function readFileHeader (); + + /** + * Flushes the file header + * + * @return void + */ + function flushFileHeader (); + + /** + * Determines whether the EOF has been reached + * + * @return $isEndOfFileReached Whether the EOF has been reached + */ + function isEndOfFileReached (); + + /** + * 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); + + /** + * 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 (); + + /** + * 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 (); + + /** + * 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); + + /** + * 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, string $rawData); + + /** + * 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); + + /** + * 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 $dataStream Data to be written + * @return mixed Number of writes bytes or false on error + * @throws InvalidArgumentException If a parameter is not valid + */ + function writeAtPosition (int $seekPosition, string $dataStream); + +} diff --git a/framework/main/interfaces/filesystem/class_Filesystem.php b/framework/main/interfaces/filesystem/class_Filesystem.php index e3b94b93..a2877ab1 100644 --- a/framework/main/interfaces/filesystem/class_Filesystem.php +++ b/framework/main/interfaces/filesystem/class_Filesystem.php @@ -1,6 +1,6 @@ + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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 IndexableFile extends BinaryFile { + +} diff --git a/framework/main/interfaces/filesystem/stack/class_FileStacker.php b/framework/main/interfaces/filesystem/stack/class_FileStacker.php new file mode 100644 index 00000000..754df63c --- /dev/null +++ b/framework/main/interfaces/filesystem/stack/class_FileStacker.php @@ -0,0 +1,32 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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 FileStacker extends BinaryFile { + +} diff --git a/framework/main/interfaces/index/class_Indexable b/framework/main/interfaces/index/class_Indexable index 1b7f41b7..e7d65073 100644 --- a/framework/main/interfaces/index/class_Indexable +++ b/framework/main/interfaces/index/class_Indexable @@ -1,6 +1,6 @@ + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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 . + */ +trait BinaryFileTrait { + /** + * An instance of an BinaryFile class + */ + private $binaryFileInstance = NULL; + + /** + * Setter for BinaryFile instance + * + * @param $binaryFileInstance An instance of an BinaryFile class + * @return void + */ + protected final function setBinaryFileInstance (BinaryFile $binaryFileInstance) { + $this->binaryFileInstance = $binaryFileInstance; + } + + /** + * Getter for BinaryFile instance + * + * @return $binaryFileInstance An instance of an BinaryFile class + */ + public final function getBinaryFileInstance () { + return $this->binaryFileInstance; + } + +} diff --git a/framework/main/traits/index/stack/class_IndexableStackTrait.php b/framework/main/traits/index/stack/class_IndexableStackTrait.php new file mode 100644 index 00000000..15e46ac7 --- /dev/null +++ b/framework/main/traits/index/stack/class_IndexableStackTrait.php @@ -0,0 +1,55 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 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 . + */ +trait IndexableStackTrait { + /** + * An instance of an IndexableStack class + */ + private $indexInstance = NULL; + + /** + * Setter for IndexableStack instance + * + * @param $indexInstance An instance of an IndexableStack class + * @return void + */ + protected final function setIndexableStackInstance (IndexableStack $indexInstance) { + $this->indexInstance = $indexInstance; + } + + /** + * Getter for IndexableStack instance + * + * @return $indexInstance An instance of an IndexableStack class + */ + public final function getIndexableStackInstance () { + return $this->indexInstance; + } + +}