From: Roland Häder Date: Thu, 7 Jan 2021 23:48:44 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4966b4ec26e66d4ebd459ad4b75d3f520bdc6681;p=core.git Continued: - rewrote a bit class loader, it used both FrameworkBootstrap::getConfigurationInstance() and a copied instance to get configuration entries, now only the former one is used - moved constants to interface BinaryFile Signed-off-by: Roland Häder --- diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 86e22b70..3f5271a0 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -4,7 +4,6 @@ namespace Org\Mxchange\CoreFramework\Loader; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; -use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration; // Import SPL stuff use \InvalidArgumentException; @@ -16,7 +15,7 @@ use \SplFileInfo; * This class loads class include files with a specific prefix and suffix * * @author Roland Haeder - * @version 1.5.0 + * @version 1.6.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.shipsimu.org @@ -35,21 +34,29 @@ use \SplFileInfo; * along with this program. If not, see . * * ---------------------------------- - * 1.5 + * 1.6.0 + * - This class loader is now 100% singleton, no other instance is really + * required, therefore the factory method can be removed safely + * - renamed initLoader() to initClassLoader() + * - An instance of a FrameworkConfiguration is no longer set here as this + * violated the rule that there shall be no instance set of that class + * - .htaccess is marked as deprecated as this should be no longer done + * - scanClassPath() is now protected, please use other scan*() methods + * 1.5.0 * - Namespace scheme Project\Package[\SubPackage...] is fully supported and * throws an InvalidArgumentException if not present. The last part will be * always the class' name. - * 1.4 + * 1.4.0 * - Some comments improved, other minor improvements - * 1.3 + * 1.3.0 * - Constructor is now empty and factory method 'createClassLoader' is created * - renamed loadClasses to scanClassPath * - Added initLoader() - * 1.2 + * 1.2.0 * - ClassLoader rewritten to PHP SPL's own RecursiveIteratorIterator class - * 1.1 + * 1.1.0 * - loadClasses rewritten to fix some notices - * 1.0 + * 1.0.0 * - Initial release * ---------------------------------- */ @@ -191,23 +198,6 @@ class ClassLoader { } } - /** - * Creates an instance of this class loader for given configuration instance - * - * @param $configInstance Configuration class instance - * @return void - */ - public static final function createClassLoader (FrameworkConfiguration $configInstance) { - // Get a new instance - $loaderInstance = new ClassLoader(); - - // Init the instance - $loaderInstance->initLoader($configInstance); - - // Return the prepared instance - return $loaderInstance; - } - /** * Scans for all framework classes, exceptions and interfaces. * @@ -218,7 +208,7 @@ class ClassLoader { //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $loaderInstance = self::getSelfInstance(); - // Get config instance + // "Cache" configuration instance $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes @@ -261,7 +251,7 @@ class ClassLoader { //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $loaderInstance = self::getSelfInstance(); - // Get config instance + // "Cache" configuration instance $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes for the application @@ -298,7 +288,7 @@ class ClassLoader { // Trace message //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); - // Get config instance + // "Cache" configuration instance $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes for the application @@ -361,10 +351,18 @@ class ClassLoader { * * @param $className Name of the class to load * @return void + * @throws InvalidArgumentException If the class' name does not contain a namespace: Tld\Domain\Project is AT LEAST recommended! */ public static function autoLoad (string $className) { - // Trace message - //* NOISY-DEBUG: */ printf('[%s:%d]: className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className); + // The class name should contain at least 2 back-slashes, so split at them + //* NOISY-DEBUG: */ printf('[%s:%d] className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className); + $classNameParts = explode("\\", $className); + + // At least 3 parts should be there + if ((self::$strictNamingConvention === true) && (count($classNameParts) < 5)) { + // Namespace scheme is: Project\Package[\SubPackage...] + throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className)); + } // Try to include this class self::getSelfInstance()->loadClassFile($className); @@ -381,14 +379,40 @@ class ClassLoader { public static final function getSelfInstance () { // Is the instance there? if (is_null(self::$selfInstance)) { - // Get a new one - self::$selfInstance = ClassLoader::createClassLoader(FrameworkBootstrap::getConfigurationInstance()); + // Get a new one and initialize it + self::$selfInstance = new ClassLoader(); + self::$selfInstance->initClassLoader(); } // Return the instance return self::$selfInstance; } + /** + * Getter for total include counter + * + * @return $total Total loaded include files + */ + public final function getTotal () { + return $this->total; + } + + /** + * Getter for a printable list of included main/interfaces/exceptions + * + * @param $includeList A printable include list + */ + public function getPrintableIncludeList () { + // Prepare the list + $includeList = ''; + foreach ($this->loadedClasses as $classFile) { + $includeList .= basename($classFile) . '
' . PHP_EOL; + } + + // And return it + return $includeList; + } + /** * Scans recursively a local path for class files which must have a prefix and a suffix as given by $this->suffix and $this->prefix * @@ -396,7 +420,7 @@ class ClassLoader { * @param $ignoreList An optional list (array forced) of directory and file names which shall be ignored * @return void */ - public function scanClassPath (string $basePath, array $ignoreList = [] ) { + protected function scanClassPath (string $basePath, array $ignoreList = [] ) { // Is a list has been restored from cache, don't read it again if ($this->listCached === true) { // Abort here @@ -409,6 +433,8 @@ class ClassLoader { /* * Ignore .htaccess by default as it is for protection of directories * on Apache servers. + * + * @deprecated */ array_push($ignoreList, '.htaccess'); @@ -467,51 +493,22 @@ class ClassLoader { } } - /** - * Getter for total include counter - * - * @return $total Total loaded include files - */ - public final function getTotal () { - return $this->total; - } - - /** - * Getter for a printable list of included main/interfaces/exceptions - * - * @param $includeList A printable include list - */ - public function getPrintableIncludeList () { - // Prepare the list - $includeList = ''; - foreach ($this->loadedClasses as $classFile) { - $includeList .= basename($classFile) . '
' . PHP_EOL; - } - - // And return it - return $includeList; - } - /** * Initializes our loader class * - * @param $configInstance Configuration class instance * @return void */ - private function initLoader (FrameworkConfiguration $configInstance) { - // Set configuration instance - $this->configInstance = $configInstance; - + private function initClassLoader () { // Construct the FQFN for the cache if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { // Init cache instances - $this->listCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache'); - $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache'); + $this->listCacheFile = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . 'list-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache'); + $this->classCacheFile = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . 'class-' . FrameworkBootstrap::getDetectedApplicationName() . '.cache'); } // Set suffix and prefix from configuration - $this->suffix = $configInstance->getConfigEntry('class_suffix'); - $this->prefix = $configInstance->getConfigEntry('class_prefix'); + $this->suffix = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('class_suffix'); + $this->prefix = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('class_prefix'); // Set own instance self::$selfInstance = $this; @@ -547,19 +544,12 @@ class ClassLoader { * * @param $className The class that shall be loaded * @return void - * @throws InvalidArgumentException If strict-checking is enabled and class name is not following naming-convention */ private function loadClassFile (string $className) { // The class name should contain at least 2 back-slashes, so split at them //* NOISY-DEBUG: */ printf('[%s:%d] className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $className); $classNameParts = explode("\\", $className); - // At least 3 parts should be there - if ((self::$strictNamingConvention === true) && (count($classNameParts) < 5)) { - // Namespace scheme is: Project\Package[\SubPackage...] - throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className)); - } - // Get last element $shortClassName = array_pop($classNameParts); diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index 1b1594ff..8fcaeca9 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -48,68 +48,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { use StackableTrait; use IndexableTrait; - /** - * Separator for header data - */ - const SEPARATOR_HEADER_DATA = 0x01; - - /** - * Separator header->entries - */ - const SEPARATOR_HEADER_ENTRIES = 0x02; - - /** - * Separator group->hash - */ - const SEPARATOR_GROUP_HASH = 0x03; - - /** - * Separator hash->value - */ - const SEPARATOR_HASH_VALUE = 0x04; - - /** - * Separator entry->entry - */ - const SEPARATOR_ENTRIES = 0x05; - - /** - * Separator type->position - */ - const SEPARATOR_TYPE_POSITION = 0x06; - - /** - * Length of count - */ - const LENGTH_COUNT = 20; - - /** - * Length of position - */ - const LENGTH_POSITION = 20; - - /** - * Length of group - */ - const LENGTH_GROUP = 10; - - /** - * Maximum length of entry type - */ - const LENGTH_TYPE = 20; - - //***** Array elements for 'gaps' array ***** - - /** - * Start of gap - */ - const GAPS_INDEX_START = 'start'; - - /** - * End of gap - */ - const GAPS_INDEX_END = 'end'; - /** * Current seek position */ @@ -275,8 +213,8 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->gaps()=%d', count($this->gaps))); foreach ($this->gaps as $gap) { // Calculate size of found gap: end-start including both - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gap[%s]=%d,ga[%s]=%d', self::GAPS_INDEX_START, $gap[self::GAPS_INDEX_START], self::GAPS_INDEX_END, $gap[self::GAPS_INDEX_END])); - $gapsSize += ($gap[self::GAPS_INDEX_END] - $gap[self::GAPS_INDEX_START]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gap[%s]=%d,ga[%s]=%d', BinaryFile::GAPS_INDEX_START, $gap[BinaryFile::GAPS_INDEX_START], BinaryFile::GAPS_INDEX_END, $gap[BinaryFile::GAPS_INDEX_END])); + $gapsSize += ($gap[BinaryFile::GAPS_INDEX_END] - $gap[BinaryFile::GAPS_INDEX_START]); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d', $gapsSize)); @@ -336,8 +274,8 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { // Push to gaps array //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: startPosition=%d,endPosition=%d - CALLED!', $startPosition, $endPosition)); array_push($this->gaps, [ - self::GAPS_INDEX_START => $startPosition, - self::GAPS_INDEX_END => $endPosition, + BinaryFile::GAPS_INDEX_START => $startPosition, + BinaryFile::GAPS_INDEX_END => $endPosition, ]); // Trace message @@ -514,7 +452,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { } // Determine it - $isFound = (strpos($str, chr(self::SEPARATOR_ENTRIES)) !== false); + $isFound = (strpos($str, chr(BinaryFile::SEPARATOR_ENTRIES)) !== false); // Return result //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isFound=%d - EXIT!', intval($isFound))); @@ -915,7 +853,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { } // Separate data - $dataArray = explode(chr(self::SEPARATOR_ENTRIES), $data); + $dataArray = explode(chr(BinaryFile::SEPARATOR_ENTRIES), $data); // Left part is the actual block, right one the back-buffer data, if found //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray))); diff --git a/framework/main/classes/index/file/class_BaseFileIndex.php b/framework/main/classes/index/file/class_BaseFileIndex.php index d8f697a3..47cac677 100644 --- a/framework/main/classes/index/file/class_BaseFileIndex.php +++ b/framework/main/classes/index/file/class_BaseFileIndex.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Index\File; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; +use Org\Mxchange\CoreFramework\Filesystem\File\BinaryFile; use Org\Mxchange\CoreFramework\Index\BaseIndex; use Org\Mxchange\CoreFramework\Index\Indexable; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; @@ -85,11 +86,11 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // Empty file header /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: File header is empty - EXIT!'); return; - } elseif (substr($data, -1, 1) != chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) { + } elseif (substr($data, -1, 1) != chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) { // Bad last character throw new UnexpectedValueException(sprintf('data=%s does not end with "%s"', $data, - chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) + chr(BinaryFile::SEPARATOR_HEADER_ENTRIES) )); } @@ -106,7 +107,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { * 0 => magic * 1 => total entries */ - $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data); + $header = explode(chr(BinaryFile::SEPARATOR_HEADER_DATA), $data); // Check if the array has only 3 elements /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: header()=%d', count($header))); @@ -117,9 +118,9 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { } elseif ($header[0] !== Indexable::INDEX_MAGIC) { // Magic must be in first element throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], Indexable::INDEX_MAGIC)); - } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) { + } elseif (strlen($header[1]) != BinaryFile::LENGTH_COUNT) { // Length of total entries not matching - throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BaseBinaryFile::LENGTH_COUNT)); + throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BinaryFile::LENGTH_COUNT)); } // Decode count @@ -145,13 +146,13 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { Indexable::INDEX_MAGIC, // Separator header data - chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), + chr(BinaryFile::SEPARATOR_HEADER_DATA), // Total entries - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), // Separator header<->entries - chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) + chr(BinaryFile::SEPARATOR_HEADER_ENTRIES) ); // Write it to disk (header is always at seek position 0) @@ -183,9 +184,9 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { // Calculate header size $headerSize = ( strlen(Indexable::INDEX_MAGIC) + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + - BaseBinaryFile::LENGTH_COUNT + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) + strlen(chr(BinaryFile::SEPARATOR_HEADER_DATA)) + + BinaryFile::LENGTH_COUNT + + strlen(chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) ); // Set it @@ -242,9 +243,9 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calculating ...'); self::$minimumBlockLength = ( // Type - BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) + + BinaryFile::LENGTH_TYPE + strlen(chr(BinaryFile::SEPARATOR_TYPE_POSITION)) + // Position - BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)) + BinaryFile::LENGTH_POSITION + strlen(chr(BinaryFile::SEPARATOR_ENTRIES)) ); } diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index c82e62c3..badedcb7 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Stack\File; 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\Filesystem\File\BinaryFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Stack\BaseStacker; use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait; @@ -100,11 +101,11 @@ abstract class BaseFileStack extends BaseStacker { // Last character must be the separator /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: data(-1)=%s', dechex(ord(substr($data, -1, 1))))); - if (substr($data, -1, 1) !== chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) { + if (substr($data, -1, 1) !== chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) { // Not valid separator throw new UnexpectedValueException(sprintf('data=%s does not have separator=%s at the end.', $data, - BaseBinaryFile::SEPARATOR_HEADER_ENTRIES + BinaryFile::SEPARATOR_HEADER_ENTRIES )); } @@ -122,7 +123,7 @@ abstract class BaseFileStack extends BaseStacker { * 1 => total entries * 2 => current seek position */ - $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data); + $header = explode(chr(BinaryFile::SEPARATOR_HEADER_DATA), $data); // Check if the array has only 3 elements /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: header(%d)=%s', count($header), print_r($header, true))); @@ -138,19 +139,19 @@ abstract class BaseFileStack extends BaseStacker { } // Check length of count and seek position - if (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) { + if (strlen($header[1]) != BinaryFile::LENGTH_COUNT) { // Count length not valid throw new UnexpectedValueException(sprintf('header[1](%d)=%s is not expected %d length', strlen($header[1]), $header[1], - BaseBinaryFile::LENGTH_COUNT + BinaryFile::LENGTH_COUNT )); - } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_POSITION) { + } elseif (strlen($header[1]) != BinaryFile::LENGTH_POSITION) { // Position length not valid throw new UnexpectedValueException(sprintf('header[2](%d)=%s is not expected %d length', strlen($header[1]), $header[1], - BaseBinaryFile::LENGTH_POSITION + BinaryFile::LENGTH_POSITION )); } @@ -178,19 +179,19 @@ abstract class BaseFileStack extends BaseStacker { StackableFile::STACK_MAGIC, // Separator magic<->count - chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), + chr(BinaryFile::SEPARATOR_HEADER_DATA), // Padded total entries - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), // Separator count<->seek position - chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), + chr(BinaryFile::SEPARATOR_HEADER_DATA), // Padded seek position - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getSeekPosition(), 2), BinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), // Separator position<->entries - chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) + chr(BinaryFile::SEPARATOR_HEADER_ENTRIES) ); // Write it to disk (header is always at seek position 0) @@ -230,11 +231,11 @@ abstract class BaseFileStack extends BaseStacker { // Calculate header size $headerSize = ( strlen(StackableFile::STACK_MAGIC) + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + - BaseBinaryFile::LENGTH_COUNT + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + - BaseBinaryFile::LENGTH_POSITION + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) + strlen(chr(BinaryFile::SEPARATOR_HEADER_DATA)) + + BinaryFile::LENGTH_COUNT + + strlen(chr(BinaryFile::SEPARATOR_HEADER_DATA)) + + BinaryFile::LENGTH_POSITION + + strlen(chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) ); // Setting it @@ -533,11 +534,11 @@ abstract class BaseFileStack extends BaseStacker { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calculating ...'); self::$minimumBlockLength = // Length of entry group - BaseBinaryFile::LENGTH_GROUP + strlen(chr(BaseBinaryFile::SEPARATOR_GROUP_HASH)) + + BinaryFile::LENGTH_GROUP + strlen(chr(BinaryFile::SEPARATOR_GROUP_HASH)) + // Hash + value - self::getHashLength() + strlen(chr(BaseBinaryFile::SEPARATOR_HASH_VALUE)) + 1 + + self::getHashLength() + strlen(chr(BinaryFile::SEPARATOR_HASH_VALUE)) + 1 + // Final separator - strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)); + strlen(chr(BinaryFile::SEPARATOR_ENTRIES)); } // Return it @@ -700,9 +701,9 @@ abstract class BaseFileStack extends BaseStacker { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,encoded()=%d - CALLED!', $stackName, $hash, strlen($encoded))); $rawData = sprintf('%s%s%s%s%s', $stackName, - BaseBinaryFile::SEPARATOR_GROUP_HASH, + BinaryFile::SEPARATOR_GROUP_HASH, hex2bin($hash), - BaseBinaryFile::SEPARATOR_HASH_VALUE, + BinaryFile::SEPARATOR_HASH_VALUE, $encoded ); diff --git a/framework/main/interfaces/filesystem/binary/class_BinaryFile.php b/framework/main/interfaces/filesystem/binary/class_BinaryFile.php index 739a1918..cdaa2350 100644 --- a/framework/main/interfaces/filesystem/binary/class_BinaryFile.php +++ b/framework/main/interfaces/filesystem/binary/class_BinaryFile.php @@ -28,6 +28,68 @@ use Org\Mxchange\CoreFramework\Filesystem\Filesystem; * along with this program. If not, see . */ interface BinaryFile extends Filesystem { + /** + * Separator for header data + */ + const SEPARATOR_HEADER_DATA = 0x01; + + /** + * Separator header->entries + */ + const SEPARATOR_HEADER_ENTRIES = 0x02; + + /** + * Separator group->hash + */ + const SEPARATOR_GROUP_HASH = 0x03; + + /** + * Separator hash->value + */ + const SEPARATOR_HASH_VALUE = 0x04; + + /** + * Separator entry->entry + */ + const SEPARATOR_ENTRIES = 0x05; + + /** + * Separator type->position + */ + const SEPARATOR_TYPE_POSITION = 0x06; + + /** + * Length of count + */ + const LENGTH_COUNT = 20; + + /** + * Length of position + */ + const LENGTH_POSITION = 20; + + /** + * Length of group + */ + const LENGTH_GROUP = 10; + + /** + * Maximum length of entry type + */ + const LENGTH_TYPE = 20; + + //***** Array elements for 'gaps' array ***** + + /** + * Start of gap + */ + const GAPS_INDEX_START = 'start'; + + /** + * End of gap + */ + const GAPS_INDEX_END = 'end'; + /** * Reads the file header *