* Reads the file header
*
* @return void
- * @throws UnexpectedValueException If header length is invalid
+ * @throws UnexpectedValueException If header length or count of elements is invalid
*/
public function readFileHeader () {
// First rewind to beginning as the header sits at the beginning ...
$data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
// Have all requested bytes been read?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
// Invalid header length
throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
*/
$header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
- // Set it here
- $this->getIteratorInstance()->setHeader($header);
-
// Check if the array has only 3 elements
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('header(%d)=%s', count($header), print_r($header, true)));
- assert(count($header) == 2);
-
- // Check magic
- assert($header[0] == self::INDEX_MAGIC);
-
- // Check length of count
- assert(strlen($header[1]) == BaseBinaryFile::LENGTH_COUNT);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header()=%d', count($header)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header(%d)=%s', count($header), print_r($header, true)));
+ if (count($header) != 2) {
+ // Bad header
+ throw new UnexpectedValueException(sprintf('header()=%d is not expected value 2', count($header)));
+ } elseif ($header[0] !== self::INDEX_MAGIC) {
+ // Magic must be in first element
+ throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], self::INDEX_MAGIC));
+ } elseif (strlen($header[1]) != BaseBinaryFile::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));
+ }
// Decode count
$header[1] = hex2bin($header[1]);
+ // Set it here
+ $this->getIteratorInstance()->setHeader($header);
+
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
}
*/
protected function initIndex (SplFileInfo $fileInfoInstance) {
// Get a file i/o pointer instance for index file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
$fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
// Get iterator instance
// Import SPL stuff
use \BadMethodCallException;
+use \InvalidArgumentException;
/**
* A general Stacker
* @param $stackerName Name of the stack
* @param $forceReInit Force re-initialization
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws AlreadyInitializedStackerException If the stack is already initialized
*/
public function initStack (string $stackerName, bool $forceReInit = false) {
- // Is the stack already initialized?
- if (($forceReInit === false) && ($this->isStackInitialized($stackerName))) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,forceReInit=%d - CALLED!', $stackerName, intval($forceReInit)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (($forceReInit === false) && ($this->isStackInitialized($stackerName))) {
// Then throw the exception
+ // @TODO Change to BMCE
throw new AlreadyInitializedStackerException(array($this, $stackerName, $forceReInit), self::EXCEPTION_STACKER_ALREADY_INITIALIZED);
- } // END - if
+ }
// Initialize the given stack
$this->initGenericArrayKey('stacks', $stackerName, 'entries', $forceReInit);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
}
/**
* Initializes all stacks
*
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
*/
public function initStacks (array $stacks, bool $forceReInit = false) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stacks()=%d,forceReInit=%d - CALLED!', count($stacks), intval($forceReInit)));
+ if (count($stacks) == 0) {
+ // No empty stack name
+ throw new InvalidArgumentException('Array "stacks" is empty');
+ }
+
// "Walk" through all (more will be added as needed
foreach ($stacks as $stackerName) {
// Init this stack
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling this->initStack(%s,%d) ...', $stackerName, intval($forceReInit)));
$this->initStack($stackerName, $forceReInit);
- } // END - foreach
+ }
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $isInitialized Whether the stack is initialized
+ * @throws InvalidArgumentException If a parameter is invalid
*/
public function isStackInitialized (string $stackerName) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Is is there?
$isInitialized = ($this->isValidGenericArrayKey('stacks', $stackerName, 'entries'));
// Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: isInitialized=%d - EXIT!', intval($isInitialized)));
return $isInitialized;
}
*
* @param $stackerName Name of the stack
* @return $isFull Whether the stack is full
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If given stack is missing
*/
protected function isStackFull (string $stackerName) {
- // Is the stack not yet initialized?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
- } // END - if
+ }
// So, is the stack full?
$isFull = (($this->getStackCount($stackerName)) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('stacker_' . $stackerName . '_max_size'));
// Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: isFull=%d - EXIT!', intval($isFull)));
return $isFull;
}
*
* @param $stackerName Name of the stack
* @return $isEmpty Whether the stack is empty
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If given stack is missing
*/
public function isStackEmpty (string $stackerName) {
- // Is the stack not yet initialized?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
- } // END - if
+ }
// So, is the stack empty?
$isEmpty = (($this->getStackCount($stackerName)) == 0);
// Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: isEmpty=%d - EXIT!', intval($isEmpty)));
return $isEmpty;
}
*
* @param $stackerName Name of the stack
* @return $count Size of stack (array count)
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If given stack is missing
*/
public function getStackCount (string $stackerName) {
- // Is the stack not yet initialized?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
- } // END - if
+ }
// Now, count the array of entries
$count = $this->countGenericArrayElements('stacks', $stackerName, 'entries');
// Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: count=%d - EXIT!', $count));
return $count;
}
* @param $stackerName Name of the stack
* @param $value Value to add to this stacker
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
+ * @throws BadMethodCallException If given stack is missing
* @throws FullStackerException Thrown if the stack is full
*/
protected function addValue (string $stackerName, $value) {
- // Is the stack not yet initialized or full?
- if (!$this->isStackInitialized($stackerName)) {
- // Then do it here
- $this->initStack($stackerName);
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
+ // Throw an exception
+ throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackFull($stackerName)) {
// Stacker is full
throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL);
// Now add the value to the stack
$this->pushValueToGenericArrayKey('stacks', $stackerName, 'entries', $value);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
protected function getLastValue (string $stackerName) {
- // Is the stack not yet initialized or full?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
$value = $this->getGenericArrayElement('stacks', $stackerName, 'entries', $this->getStackCount($stackerName) - 1);
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
protected function getFirstValue (string $stackerName) {
- // Is the stack not yet initialized or full?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
$value = $this->getGenericArrayElement('stacks', $stackerName, 'entries', 0);
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value "poped" from array
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
protected function popLast (string $stackerName) {
- // Is the stack not yet initialized or full?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
}
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
- return $this->popGenericArrayElement('stacks', $stackerName, 'entries');
+ $value = $this->popGenericArrayElement('stacks', $stackerName, 'entries');
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
+ return $value;
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value "shifted" from array
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
protected function popFirst (string $stackerName) {
- // Is the stack not yet initialized or full?
- if (!$this->isStackInitialized($stackerName)) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (!$this->isStackInitialized($stackerName)) {
// Throw an exception
throw new BadMethodCallException(sprintf('stackerName=%s not yet initialized but method called.', $stackerName), self::EXCEPTION_NO_STACKER_FOUND);
} elseif ($this->isStackEmpty($stackerName)) {
}
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
- return $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
+ $value = $this->shiftGenericArrayElement('stacks', $stackerName, 'entries');
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
+ return $value;
}
}
// Own namespace
namespace Org\Mxchange\CoreFramework\Stack;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A FiFo Stacker class
*
* @param $stackerName Name of the stack
* @param $value Value to push on it
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws StackerFullException If the stack is full
*/
public function pushNamed (string $stackerName, $value) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Call the protected method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
parent::addValue($stackerName, $value);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value of the current stack entry
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function popNamed (string $stackerName) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Get the value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling this->getNamed(%s) ...', $stackerName));
$value = $this->getNamed($stackerName);
// Call the protected method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::popFirst(%s) ...', $stackerName));
parent::popFirst($stackerName);
// Return the value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function getNamed (string $stackerName) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Call the protected method
- return parent::getFirstValue($stackerName);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::getFirstValue(%s) ...', $stackerName));
+ $value = parent::getFirstValue($stackerName);
+
+ // Return value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
+ return $value;
}
}
*/
public function readFileHeader () {
// First rewind to beginning as the header sits at the beginning ...
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: CALLED!', __METHOD__, __LINE__));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
$this->getIteratorInstance()->rewind();
// Then read it (see constructor for calculation)
*/
public function flushFileHeader () {
// Put all informations together
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: CALLED!', __METHOD__, __LINE__));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
$header = sprintf('%s%s%s%s%s%s',
// Magic
StackableFile::STACK_MAGIC,
$this->getIteratorInstance()->writeData(0, $header, false);
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: EXIT!', __METHOD__, __LINE__));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
}
/**
// And set it here
$this->setIndexInstance($indexInstance);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
}
/**
* @param $value Value to add to this stacker
* @return void
* @throws FullStackerException If the stack is full
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws InvalidArgumentException Not all variable types are wanted here
*/
protected function addValue (string $stackerName, $value) {
- // Do some tests
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('stackerName=%s,value[%s]=%s - CALLED!', $stackerName, gettype($value), print_r($value, true)));
- if ($this->isStackFull($stackerName)) {
+ // 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)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif ($this->isStackFull($stackerName)) {
// Stacker is full
throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL);
} elseif (is_resource($value) || is_object($value)) {
// Add the hash and gap position to the index
$this->getIndexInstance()->addHashToIndex($stackerName, $data);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws BadMethodCallException If the stack is empty
*/
protected function getLastValue (string $stackerName) {
- // Is the stack not yet initialized or full?
- if ($this->isStackEmpty($stackerName)) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
- } // END - if
+ }
// Now get the last value
/* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
$value = NULL;
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws BadMethodCallException If the stack is empty
*/
protected function getFirstValue (string $stackerName) {
- // Is the stack not yet initialized or full?
- if ($this->isStackEmpty($stackerName)) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
- } // END - if
+ }
// Now get the first value
/* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
$value = NULL;
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value "poped" from array
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws BadMethodCallException If the stack is empty
*/
protected function popLast (string $stackerName) {
- // Is the stack not yet initialized or full?
- if ($this->isStackEmpty($stackerName)) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
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
/* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
*
* @param $stackerName Name of the stack
* @return $value Value "shifted" from array
+ * @throws InvalidArgumentException If a parameter is not valid
* @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)) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif ($this->isStackEmpty($stackerName)) {
// Throw an exception
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
/* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
*
* @param $stackerName Name of the stack
* @return $isFull Whether the stack is full
+ * @throws InvalidArgumentException If a parameter is not valid
*/
protected function isStackFull (string $stackerName) {
- // File-based stacks will only run full if the disk space is low.
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// @TODO Please implement this, returning false
+ /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
$isFull = false;
// Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: isFull=%d - EXIT!', intval($isFull)));
return $isFull;
}
*
* @param $stackerName Name of the stack
* @return $isEmpty Whether the stack is empty
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws BadMethodCallException If given stack is missing
*/
public function isStackEmpty (string $stackerName) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// So, is the stack empty?
$isEmpty = (($this->getStackCount($stackerName)) == 0);
// Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: isEmpty=%d - EXIT!', intval($isEmpty)));
return $isEmpty;
}
*/
public function getStackCount (string $stackerName) {
// Now, simply return the found count value, this must be up-to-date then!
- return $this->getIteratorInstance()->getCounter();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ $count = $this->getIteratorInstance()->getCounter();
+
+ // Return count
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: count=%d - EXIT!', $count));
+ return $count;
}
/**
*/
public function calculateMinimumBlockLength () {
// Calulcate it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
$length =
// Length of entry group
BaseBinaryFile::LENGTH_GROUP + strlen(chr(BaseBinaryFile::SEPARATOR_GROUP_HASH)) +
strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES));
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: length=%d - EXIT!', $length));
return $length;
}
*/
public function getFileSize () {
// Call iterator's method
- return $this->getIteratorInstance()->getFileSize();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
+ $size = $this->getIteratorInstance()->getFileSize();
+
+ // Return size
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: size=%d - EXIT!', $size));
+ return $size;
}
/**
$gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
// Gap position cannot be smaller than header length + 1
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: gapPosition=%d', $gapPosition));
if ($gapPosition <= $this->getIteratorInstance()->getHeaderSize()) {
// Improper gap position
throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is not larger than headerSize=%d',
use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
// Import SPL stuff
+use \InvalidArgumentException;
use \SplFileInfo;
/**
* @param $fileInfoInstance An instance of a SplFileInfo class
* @param $type Type of this stack (e.g. url_source for URL sources)
* @return $stackInstance An instance of a StackableFile class
+ * @throws InvalidArgumentException If a parameter is invalid
*/
- public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, $type) {
+ public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, string $type) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: fileInfoInstance[%s]=%s,type=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $type));
+ if (empty($type)) {
+ // No empty type
+ throw new InvalidArgumentException('Parameter "type" is empty');
+ }
+
// Get new instance
$stackInstance = new FiFoFileStack();
// Init this stack
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Calling stackInstance->initFileStack([%s]=%s,%s) ...', get_class($fileInfoInstance), $fileInfoInstance, $type));
$stackInstance->initFileStack($fileInfoInstance, $type);
// Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackInstance=%s - EXIT!', $stackInstance->__toString()));
return $stackInstance;
}
* @param $stackerName Name of the stack
* @param $value Value to push on it
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws StackerFullException If the stack is full
*/
public function pushNamed (string $stackerName, $value) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ } elseif (is_object($value) || is_resource($value)) {
+ // Those types for $value are not allowed
+ throw new InvalidArgumentException(sprintf('value[]=%s is not valid', gettype($value)));
+ }
+
// Call the protected method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
parent::addValue($stackerName, $value);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value of the current stack entry
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function popNamed (string $stackerName) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Get the value
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: this->getNamed(%s) ...', $stackerName));
$value = $this->getNamed($stackerName);
// Call the protected method
parent::popFirst($stackerName);
// Return the value
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function getNamed (string $stackerName) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Call the protected method
- return parent::getFirstValue($stackerName);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: parent::getFirstValue(%s) ...', $stackerName));
+ $value = parent::getFirstValue($stackerName);
+
+ // Return the value
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
+ return $value;
}
/**
*
* @param $seekPosition Seek position in file
* @return $status Status of this operation
+ * @throws InvalidArgumentException If a parameter is invalid
*/
- public function seek ($seekPosition) {
+ public function seek (int $seekPosition) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d - CALLED!', $seekPosition));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ }
+
+ // @TODO Unfinished method or invoke inner iterator's method?
$this->partialStub('seekPosition=' . $seekPosition);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: EXIT!');
}
/**
*/
public function size () {
// Call the iterator instance
- return $this->getIteratorInstance()->size();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FIFO-FILE-STACK: CALLED!');
+ $size = $this->getIteratorInstance()->size();
+
+ // Return size
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: size=%d - EXIT!', $size));
+ return $size;
}
}
*/
public static final function createFiLoStacker () {
// Get a new instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILO-FILE-STACK: CALLED!');
$stackInstance = new FiLoStacker();
// Init the generic stacker
$stackInstance->initStack('generic');
// Return the prepared instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: stackInstance=%s - EXIT!', $stackInstance->__toString()));
return $stackInstance;
}
* @param $stackerName Name of the stack
* @param $value Value to push on it
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws StackerFullException If the stack is full
*/
public function pushNamed (string $stackerName, $value) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Call the protected method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
parent::addValue($stackerName, $value);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILO-FILE-STACK: EXIT!');
}
/**
*
* @param $stackerName Name of the stack
* @return $value Value of the current stack entry
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function popNamed (string $stackerName) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Get the value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: this->getNamed(%s) ...', $stackerName));
$value = $this->getNamed($stackerName);
// Call the protected method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: parent::popLast(%s) ...', $stackerName));
parent::popLast($stackerName);
// Return the value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
return $value;
}
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
+ * @throws InvalidArgumentException If a parameter is invalid
* @throws BadMethodCallException If the named stacker was not found
* @throws BadMethodCallException If the named stacker is empty
*/
public function getNamed (string $stackerName) {
+ // Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
+ if (empty($stackerName)) {
+ // No empty stack name
+ throw new InvalidArgumentException('Parameter "stackerName" is empty');
+ }
+
// Call the protected method
- return parent::getLastValue($stackerName);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: parent::getLastValue(%s) ...', $stackerName));
+ $value = parent::getLastValue($stackerName);
+
+ // Return the value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILO-FILE-STACK: value[]=%s - EXIT!', gettype($value)));
+ return $value;
}
}