<?php
// Own namespace
-namespace Org\Mxchange\CoreFramework\Stacker\Filesystem;
+namespace Org\Mxchange\CoreFramework\Stack\File;
// Import framework stuff
use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
-use Org\Mxchange\CoreFramework\Filesystem\Stack\StackableFile;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
use Org\Mxchange\CoreFramework\Registry\Registerable;
-use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStack;
+use Org\Mxchange\CoreFramework\Stack\File\BaseFileStack;
+use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
// Import SPL stuff
+use \InvalidArgumentException;
+use \OutOfBoundsException;
use \SplFileInfo;
/**
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2017 Core Developer Team
+ * @copyright Copyright (c) 2023 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @return void
*/
- protected function __construct () {
+ private function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
* @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', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Get new instance
$stackInstance = new FiFoFileStack();
// Init this stack
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Invoking 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 StackerFullException If the stack is full
+ * @throws InvalidArgumentException If a parameter is invalid
+ * @throws BadMethodCallException If the stack is full
*/
- public function pushNamed ($stackerName, $value) {
+ 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', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } 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
- parent::addValue($stackerName, $value);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: Invoking parent::addValueToStack(%s,%s) ...', $stackerName, gettype($value)));
+ parent::addValueToStack($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 NoStackerException If the named stacker was not found
- * @throws EmptyStackerException If the named stacker is empty
+ * @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 ($stackerName) {
+ 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', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// 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 NoStackerException If the named stacker was not found
- * @throws EmptyStackerException If the named stacker is empty
+ * @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 ($stackerName) {
+ 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', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// 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;
}
/**
* Seeks to given position
*
* @param $seekPosition Seek position in file
+ * @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of this operation
+ * @throws OutOfBoundsException If the position is not seekable
*/
- public function seek ($seekPosition) {
- $this->partialStub('seekPosition=' . $seekPosition);
+ public function seek (int $seekPosition, int $whence = SEEK_SET) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ }
+
+ // @TODO Unfinished method or invoke inner iterator's method?
+ DebugMiddleware::getSelfInstance()->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;
}
}