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;
}
}