- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] header(%d)=%s', __METHOD__, __LINE__, count($header), print_r($header, true)));
- assert(count($header) == 3);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
-
- // Check magic
- assert($header[0] == self::STACK_MAGIC);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
-
- // Check length of count and seek position
- assert(strlen($header[1]) == BaseBinaryFile::LENGTH_COUNT);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
- assert(strlen($header[2]) == BaseBinaryFile::LENGTH_POSITION);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: HEADER_STACK_ELEMENT_COUNT=%d,header()=%d', BinaryFile::HEADER_STACK_ELEMENT_COUNT, count($header)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: HEADER_STACK_ELEMENT_COUNT=%d,header(%d)=%s', BinaryFile::HEADER_STACK_ELEMENT_COUNT, count($header), print_r($header, true)));
+ if (count($header) != BinaryFile::HEADER_STACK_ELEMENT_COUNT) {
+ // Header array count is not expected
+ throw new UnexpectedValueException(sprintf('data=%s has %d elements, but expected is %d',
+ $data,
+ count($header),
+ BinaryFile::HEADER_STACK_ELEMENT_COUNT
+ ));
+ } elseif ($header[BinaryFile::HEADER_NAME_MAGIC] != StackableFile::STACK_MAGIC) {
+ // Bad magic
+ throw new InvalidMagicException($data, self::EXCEPTION_BAD_MAGIC);
+ } elseif (strlen($header[BinaryFile::HEADER_NAME_TOTAL_ENTRIES]) != BinaryFile::LENGTH_COUNT) {
+ // Count length not valid
+ throw new UnexpectedValueException(sprintf('header[%s](%d)=%s is not expected %d length',
+ BinaryFile::HEADER_NAME_TOTAL_ENTRIES,
+ strlen($header[BinaryFile::HEADER_NAME_TOTAL_ENTRIES]),
+ $header[BinaryFile::HEADER_NAME_TOTAL_ENTRIES],
+ BinaryFile::LENGTH_COUNT
+ ));
+ } elseif (strlen($header[BinaryFile::HEADER_NAME_SEEK_POSITION]) != BinaryFile::LENGTH_POSITION) {
+ // Position length not valid
+ throw new UnexpectedValueException(sprintf('header[%s](%d)=%s is not expected %d length',
+ BinaryFile::HEADER_NAME_SEEK_POSITION,
+ strlen($header[BinaryFile::HEADER_NAME_SEEK_POSITION]),
+ $header[BinaryFile::HEADER_NAME_SEEK_POSITION],
+ BinaryFile::LENGTH_POSITION
+ ));
+ }