From 868c877607670760eb36e63ebeb1a04237907be9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 8 Jul 2018 07:04:51 +0200 Subject: [PATCH] Continued: - it is getFileObject() not getPointer() - also let that method invoke wrapped file pointer instance' same method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- framework/loader/class_ClassLoader.php | 2 +- .../file_directories/class_BaseAbstractFile.php | 7 +++---- .../classes/file_directories/class_BaseFileIo.php | 2 +- .../directory/class_FrameworkDirectoryPointer.php | 2 +- .../raw/class_FrameworkRawFileInputPointer.php | 2 +- .../text/class_FrameworkTextFileInputPointer.php | 15 ++++++++++++--- .../io/class_FrameworkFileInputOutputPointer.php | 2 +- .../raw/class_FrameworkRawFileOutputPointer.php | 2 +- .../text/class_FrameworkTextFileOutputPointer.php | 2 +- .../text/input/class_BaseInputTextFile.php | 9 ++++++--- .../text/input/csv/class_CsvInputFile.php | 9 ++++++--- .../index/file_stack/class_FileStackIndex.php | 2 +- .../stacker/file/fifo/class_FiFoFileStack.php | 2 +- .../main/interfaces/io/class_CloseableFile.php | 2 +- .../interfaces/io/pointer/class_InputPointer.php | 2 +- .../interfaces/io/pointer/class_OutputPointer.php | 2 +- .../console/class_TestsConsoleCommandResolver.php | 1 + 17 files changed, 40 insertions(+), 25 deletions(-) diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 330cdaa0..5035d3f8 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -455,7 +455,7 @@ class ClassLoader { $currentEntry = $iteratorInstance->current(); // Get filename from iterator which is the class' name (according naming-convention) - $fileName = $currentEntry->getFileName(); + $fileName = $currentEntry->getFilename(); // Current entry must be a file, not smaller than 100 bytes and not on ignore list if ((!$currentEntry->isFile()) || (in_array($fileName, $this->ignoreList)) || ($currentEntry->getSize() < 100)) { diff --git a/framework/main/classes/file_directories/class_BaseAbstractFile.php b/framework/main/classes/file_directories/class_BaseAbstractFile.php index 92b3f114..29517f42 100644 --- a/framework/main/classes/file_directories/class_BaseAbstractFile.php +++ b/framework/main/classes/file_directories/class_BaseAbstractFile.php @@ -105,10 +105,9 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * Getter for the file object * * @return $fileObject An instance of a SplFileObject - * @throws UnsupportedOperationException If this method is called */ public final function getFileObject () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + return $this->getPointerInstance()->getFileObject(); } /** @@ -144,7 +143,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * * @return mixed The result of fread() * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set */ public function readFromFile () { @@ -158,7 +157,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set * an invalid file resource */ diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index ce65bd89..f45b5ea3 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -71,7 +71,7 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl * to empty. * * @return void - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws LogicException If there is no object being set */ public function closeFile () { diff --git a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php index 4c033024..d7f346a1 100644 --- a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -161,7 +161,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: fileInfoInstance[' . gettype($fileInfoInstance) . ']=' . $fileInfoInstance . ',isDot=' . intval($this->getDirectoryIteratorInstance()->isDot())); // Is it a dot-directory or excluded? - if (($this->getDirectoryIteratorInstance()->isDot()) || (in_array($fileInfoInstance, $except))) { + if (($this->getDirectoryIteratorInstance()->isDot()) && (!in_array($fileInfoInstance, $except))) { // To next entry $this->getDirectoryIteratorInstance()->next(); diff --git a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php index fc3ab6db..3de4dc74 100644 --- a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php +++ b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php @@ -92,7 +92,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { * Read data a file pointer * * @return mixed The result of fread() - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws LogicException If there is no object being set */ public function readFromFile () { diff --git a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php index 1b3c88ee..00706310 100644 --- a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -12,6 +12,9 @@ use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; +// Import SPL stuff +use \SplFileInfo; + /** * A class for reading text files * @@ -54,7 +57,8 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { * @throws FileReadProtectedException If the file cannot be read from * @return void */ - public static final function createFrameworkTextFileInputPointer ($infoInstance) { + public static final function createFrameworkTextFileInputPointer (SplFileInfo $infoInstance) { + // Check parameter if (!FrameworkBootstrap::isReachableFilePath($infoInstance)) { // File cannot be reached throw new FileIoException($infoInstance, self::EXCEPTION_FILE_NOT_REACHABLE); @@ -68,6 +72,11 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { // Try to open a handler $fileObject = $infoInstance->openFile('r'); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TEXT-FILE-INPUT: fileObject[]=' . gettype($fileObject)); + + // Is it valid? if ((is_null($fileObject)) || ($fileObject === false)) { // Something bad happend throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); @@ -77,7 +86,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { $pointerInstance = new FrameworkTextFileInputPointer(); // Set file pointer and file name - $pointerInstance->setPointer($fileObject); + $pointerInstance->setFileObject($fileObject); // Return the instance return $pointerInstance; @@ -108,7 +117,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { * * @param $bytes Amount of bytes to read or whole line (only text files) * @return $data Data read from file - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws InvalidResourceException If there is no object being set */ public function read ($bytes = NULL) { diff --git a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php index 971b3aca..1217e83a 100644 --- a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -102,7 +102,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP * * @return void * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @todo Add more checks */ private function validateFilePointer () { diff --git a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php index 81bd3433..7c9b1901 100644 --- a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php @@ -83,7 +83,7 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer * * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws LogicException If there is no object being set */ public function writeToFile ($dataStream) { diff --git a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php index d94ec9ce..11dd3735 100644 --- a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php @@ -86,7 +86,7 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer * * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws LogicException If there is no object being set */ public function writeToFile ($dataStream) { diff --git a/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php b/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php index 1767a55a..9216f12a 100644 --- a/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php +++ b/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php @@ -6,6 +6,9 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Text; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\File\BaseTextFile; +// Import SPL stuff +use \SplFileInfo; + /** * A general text input file class * @@ -43,12 +46,12 @@ abstract class BaseInputTextFile extends BaseTextFile { /** * Initializes this text file for reading * - * @param $fileName File's name + * @param $infoInstance An instance of a SplFileInfo class * @return void */ - protected function initFile ($fileName) { + protected function initFile (SplFileInfo $infoInstance) { // Get a file i/o pointer instance - $pointerInstance = ObjectFactory::createObjectByConfiguredName('text_file_input_class', array($fileName)); + $pointerInstance = ObjectFactory::createObjectByConfiguredName('text_file_input_class', array($infoInstance)); // ... and set it here $this->setPointerInstance($pointerInstance); diff --git a/framework/main/classes/file_directories/text/input/csv/class_CsvInputFile.php b/framework/main/classes/file_directories/text/input/csv/class_CsvInputFile.php index 3343c6dd..efd42eb1 100644 --- a/framework/main/classes/file_directories/text/input/csv/class_CsvInputFile.php +++ b/framework/main/classes/file_directories/text/input/csv/class_CsvInputFile.php @@ -6,6 +6,9 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Input\Csv; use Org\Mxchange\CoreFramework\Filesystem\Text\BaseInputTextFile; use Org\Mxchange\CoreFramework\Stream\Filesystem\CsvInputStreamer; +// Import SPL stuff +use \SplFileInfo; + /** * A CSV file input class for writing CSV files * @@ -42,15 +45,15 @@ class CsvInputFile extends BaseInputTextFile implements CsvInputStreamer { /** * Creates an instance of this File class and prepares it for usage * - * @param $fileName Name of the index file + * @param $infoInstance An instance of a SplFileInfo class * @return $fileInstance An instance of this File class */ - public final static function createCsvInputFile ($fileName) { + public final static function createCsvInputFile (SplFileInfo $infoInstance) { // Get a new instance $fileInstance = new CsvInputFile(); // Init this abstract file - $fileInstance->initFile($fileName); + $fileInstance->initFile($infoInstance); // Return the prepared instance return $fileInstance; diff --git a/framework/main/classes/index/file_stack/class_FileStackIndex.php b/framework/main/classes/index/file_stack/class_FileStackIndex.php index 7d330609..7deb716a 100644 --- a/framework/main/classes/index/file_stack/class_FileStackIndex.php +++ b/framework/main/classes/index/file_stack/class_FileStackIndex.php @@ -6,7 +6,7 @@ namespace Org\Mxchange\CoreFramework\Index\Stack; use Org\Mxchange\CoreFramework\Index\BaseIndex; use Org\Mxchange\CoreFramework\Index\Indexable; use Org\Mxchange\CoreFramework\Registry\Registerable; -use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStacker; +use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStack; use Org\Mxchange\CoreFramework\Stacker\Index\IndexableStack; // Import SPL stuff diff --git a/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php b/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php index 9994e38c..d015cf71 100644 --- a/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php +++ b/framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php @@ -6,7 +6,7 @@ namespace Org\Mxchange\CoreFramework\Stacker\Filesystem; use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock; use Org\Mxchange\CoreFramework\Filesystem\Stack\StackableFile; use Org\Mxchange\CoreFramework\Registry\Registerable; -use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStacker; +use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStack; // Import SPL stuff use \SplFileInfo; diff --git a/framework/main/interfaces/io/class_CloseableFile.php b/framework/main/interfaces/io/class_CloseableFile.php index ebfc1c3c..1d4d0d9b 100644 --- a/framework/main/interfaces/io/class_CloseableFile.php +++ b/framework/main/interfaces/io/class_CloseableFile.php @@ -34,7 +34,7 @@ interface CloseableFile extends FrameworkInterface { * to empty. * * @return void - * @throws NullPointerException If the file pointer instance is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws InvalidResourceException If there is being set */ function closeFile (); diff --git a/framework/main/interfaces/io/pointer/class_InputPointer.php b/framework/main/interfaces/io/pointer/class_InputPointer.php index 334ed78c..47a89350 100644 --- a/framework/main/interfaces/io/pointer/class_InputPointer.php +++ b/framework/main/interfaces/io/pointer/class_InputPointer.php @@ -49,7 +49,7 @@ interface InputPointer extends StreamableInput, FilePointer { * @param $bytes Amount of bytes to read or whole line (only text files) * @return $data Data read from file * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set */ function read ($bytes = NULL); diff --git a/framework/main/interfaces/io/pointer/class_OutputPointer.php b/framework/main/interfaces/io/pointer/class_OutputPointer.php index 403e6625..f4a240bb 100644 --- a/framework/main/interfaces/io/pointer/class_OutputPointer.php +++ b/framework/main/interfaces/io/pointer/class_OutputPointer.php @@ -35,7 +35,7 @@ interface OutputPointer extends StreamableOutput, FilePointer { * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set * an invalid file resource */ diff --git a/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php index 925bb04e..7220e3e0 100644 --- a/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php +++ b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php @@ -69,6 +69,7 @@ class TestsConsoleCommandResolver extends BaseCommandResolver implements Command // Set namespace for command $resolverInstance->setNamespace('Org\Mxchange\CoreFramework\Tests\Command'); + $resolverInstance->setCommandName($commandName); // Return the prepared instance return $resolverInstance; -- 2.39.5