X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;h=a5a2eaa69d76f30d7ff437ed9586919073a832d9;hb=c1841c5d8ad644456ea408caf315e858d89fc555;hp=d990a375f07525492bbb8f9c84fa98afe85bef0d;hpb=2c3a0173e6dbfab3093b01643dc03110ddb4538b;p=core.git diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index d990a375..a5a2eaa6 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -1,16 +1,17 @@ . */ -abstract class BaseFileStack extends BaseStacker { +abstract class BaseFileStack extends BaseStacker implements StackableFile { // Load traits use IteratorTrait; // Exception codes const EXCEPTION_BAD_MAGIC = 0xe100; - /** - * Magic for this stack - */ - const STACK_MAGIC = 'STACKv0.1'; - - /** - * Name of array index for gap position - */ - const ARRAY_INDEX_GAP_POSITION = 'gap'; - - /** - * Name of array index for hash - */ - const ARRAY_INDEX_HASH = 'hash'; - - /** - * Name of array index for length of raw data - */ - const ARRAY_INDEX_DATA_LENGTH = 'length'; - /** * An instance of an Indexable class */ @@ -154,9 +135,6 @@ abstract class BaseFileStack extends BaseStacker { */ $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data); - // Set header here - $this->getIteratorInstance()->setHeader($header); - // 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))); if (count($header) != 3) { @@ -165,7 +143,7 @@ abstract class BaseFileStack extends BaseStacker { $data, count($header) )); - } elseif ($header[0] != self::STACK_MAGIC) { + } elseif ($header[0] != StackableFile::STACK_MAGIC) { // Bad magic throw new InvalidMagicException($data, self::EXCEPTION_BAD_MAGIC); } @@ -191,6 +169,9 @@ abstract class BaseFileStack extends BaseStacker { $header[1] = hex2bin($header[1]); $header[2] = hex2bin($header[2]); + // Set header here + $this->getIteratorInstance()->setHeader($header); + // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: EXIT!', __METHOD__, __LINE__)); } @@ -205,7 +186,7 @@ abstract class BaseFileStack extends BaseStacker { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: CALLED!', __METHOD__, __LINE__)); $header = sprintf('%s%s%s%s%s%s', // Magic - self::STACK_MAGIC, + StackableFile::STACK_MAGIC, // Separator magic<->count chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), @@ -251,7 +232,7 @@ abstract class BaseFileStack extends BaseStacker { // Calculate header size $this->getIteratorInstance()->setHeaderSize( - strlen(self::STACK_MAGIC) + + strlen(StackableFile::STACK_MAGIC) + strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + BaseBinaryFile::LENGTH_COUNT + strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + @@ -322,13 +303,13 @@ abstract class BaseFileStack extends BaseStacker { * * @param $stackerName Name of the stack * @return $value Value of last added value - * @throws EmptyStackerException If the stack is empty + * @throws BadMethodCallException If the stack is empty */ protected function getLastValue (string $stackerName) { // Is the stack not yet initialized or full? if ($this->isStackEmpty($stackerName)) { // Throw an exception - throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); } // END - if // Now get the last value @@ -344,13 +325,13 @@ abstract class BaseFileStack extends BaseStacker { * * @param $stackerName Name of the stack * @return $value Value of last added value - * @throws EmptyStackerException If the stack is empty + * @throws BadMethodCallException If the stack is empty */ protected function getFirstValue (string $stackerName) { // Is the stack not yet initialized or full? if ($this->isStackEmpty($stackerName)) { // Throw an exception - throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); } // END - if // Now get the first value @@ -366,13 +347,13 @@ abstract class BaseFileStack extends BaseStacker { * * @param $stackerName Name of the stack * @return $value Value "poped" from array - * @throws EmptyStackerException If the stack is empty + * @throws BadMethodCallException If the stack is empty */ protected function popLast (string $stackerName) { // Is the stack not yet initialized or full? if ($this->isStackEmpty($stackerName)) { // Throw an exception - throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); } // END - if // Now, remove the last entry, we don't care about the return value here, see elseif() block above @@ -385,13 +366,13 @@ abstract class BaseFileStack extends BaseStacker { * * @param $stackerName Name of the stack * @return $value Value "shifted" from array - * @throws EmptyStackerException If the named stacker is empty + * @throws BadMethodCallException If the named stacker is empty */ protected function popFirst (string $stackerName) { // Is the stack not yet initialized or full? if ($this->isStackEmpty($stackerName)) { // Throw an exception - throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); + throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY); } // END - if // Now, remove the last entry, we don't care about the return value here, see elseif() block above @@ -668,9 +649,9 @@ abstract class BaseFileStack extends BaseStacker { // Return gap position, hash and length of raw data /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $hash, strlen($rawData))); return [ - self::ARRAY_INDEX_GAP_POSITION => $gapPosition, - self::ARRAY_INDEX_HASH => $hash, - self::ARRAY_INDEX_DATA_LENGTH => strlen($rawData), + self::ARRAY_NAME_GAP_POSITION => $gapPosition, + self::ARRAY_NAME_HASH => $hash, + self::ARRAY_NAME_DATA_LENGTH => strlen($rawData), ]; }