From 0a638eea103f0f2b6c48374cb8d01e68893f5a65 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 16 May 2014 23:49:45 +0200 Subject: [PATCH] Added new interfaces for file i/o classes. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../interfaces/io/file/handler/.htaccess | 1 + .../io/{ => file/handler}/class_IoHandler.php | 21 +--------- inc/classes/interfaces/io/pointer/.htaccess | 1 + .../io/pointer/class_InputPointer.php | 37 ++++++++++++++++++ .../io/pointer/class_OutputPointer.php | 39 +++++++++++++++++++ .../interfaces/io/pointer/io/.htaccess | 1 + .../pointer/io/class_InputOutputPointer.php | 28 +++++++++++++ .../main/class_BaseFrameworkSystem.php | 10 ++--- .../input/class_FrameworkFileInputPointer.php | 2 +- .../class_FrameworkFileInputOutputPointer.php | 2 +- .../io_handler/class_FileIoStream.php | 2 +- .../class_FrameworkFileOutputPointer.php | 2 +- .../main/iterator/io/class_FileIoIterator.php | 4 +- .../middleware/io/class_FileIoHandler.php | 10 +---- 14 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 inc/classes/interfaces/io/file/handler/.htaccess rename inc/classes/interfaces/io/{ => file/handler}/class_IoHandler.php (71%) create mode 100644 inc/classes/interfaces/io/pointer/.htaccess create mode 100644 inc/classes/interfaces/io/pointer/class_InputPointer.php create mode 100644 inc/classes/interfaces/io/pointer/class_OutputPointer.php create mode 100644 inc/classes/interfaces/io/pointer/io/.htaccess create mode 100644 inc/classes/interfaces/io/pointer/io/class_InputOutputPointer.php diff --git a/inc/classes/interfaces/io/file/handler/.htaccess b/inc/classes/interfaces/io/file/handler/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/io/file/handler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/io/class_IoHandler.php b/inc/classes/interfaces/io/file/handler/class_IoHandler.php similarity index 71% rename from inc/classes/interfaces/io/class_IoHandler.php rename to inc/classes/interfaces/io/file/handler/class_IoHandler.php index 55b5590b..0463b826 100644 --- a/inc/classes/interfaces/io/class_IoHandler.php +++ b/inc/classes/interfaces/io/file/handler/class_IoHandler.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface IoHandler extends FrameworkInterface { +interface IoHandler extends FileInputStreamer, FileOutputStreamer { /** * Setter for the *real* file input instance * @@ -51,23 +51,6 @@ interface IoHandler extends FrameworkInterface { * @return $outputStream The *real* file-output class */ function getOutputStream (); - - /** - * Saves a file with data by using the current output stream - * - * @param $fileName Name of the file - * @param $dataStream File data stream - * @param $objectInstance An instance of a FrameworkInterface class (default: NULL) - * @return void - */ - function saveFile ($fileName, $dataStream, FrameworkInterface $objectInstance = NULL); - - /** Loads data from a file over the input handler - * - * @param $fqfn Given full-qualified file name (FQFN) to load - * @return $array Array with the file contents - */ - function loadFileContents ($fqfn); } // [EOF] diff --git a/inc/classes/interfaces/io/pointer/.htaccess b/inc/classes/interfaces/io/pointer/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/io/pointer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/io/pointer/class_InputPointer.php b/inc/classes/interfaces/io/pointer/class_InputPointer.php new file mode 100644 index 00000000..d312dc9f --- /dev/null +++ b/inc/classes/interfaces/io/pointer/class_InputPointer.php @@ -0,0 +1,37 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface InputPointer extends Streamable { + /** + * Read data a file pointer + * + * @return mixed The result of fread() + * @throws NullPointerException If the file pointer instance + * is not set by setPointer() + * @throws InvalidResourceException If there is being set + */ + function readFromFile (); +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/io/pointer/class_OutputPointer.php b/inc/classes/interfaces/io/pointer/class_OutputPointer.php new file mode 100644 index 00000000..8d367ebe --- /dev/null +++ b/inc/classes/interfaces/io/pointer/class_OutputPointer.php @@ -0,0 +1,39 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface OutputPointer extends Streamable { + /** + * Write data to a file pointer + * + * @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 InvalidResourceException If there is being set + * an invalid file resource + */ + function writeToFile ($dataStream); +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/io/pointer/io/.htaccess b/inc/classes/interfaces/io/pointer/io/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/io/pointer/io/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/io/pointer/io/class_InputOutputPointer.php b/inc/classes/interfaces/io/pointer/io/class_InputOutputPointer.php new file mode 100644 index 00000000..6c2de09c --- /dev/null +++ b/inc/classes/interfaces/io/pointer/io/class_InputOutputPointer.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface InputOutputPointer extends InputPointer, OutputPointer { +} + +// [EOF] +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index b13875fa..abcefc8c 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1224,19 +1224,19 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } /** - * Setter for FrameworkFileInputOutputPointer instance + * Setter for InputOutputPointer instance * - * @param $pointerInstance An instance of an FrameworkFileInputOutputPointer + * @param $pointerInstance An instance of an InputOutputPointer * @return void */ - protected final function setPointerInstance (FrameworkFileInputOutputPointer $pointerInstance) { + protected final function setPointerInstance (InputOutputPointer $pointerInstance) { $this->pointerInstance = $pointerInstance; } /** - * Getter for FrameworkFileInputOutputPointer instance + * Getter for InputOutputPointer instance * - * @return $pointerInstance An instance of an FrameworkFileInputOutputPointer + * @return $pointerInstance An instance of an InputOutputPointer */ public final function getPointerInstance () { return $this->pointerInstance; diff --git a/inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php b/inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php index f70ef5a1..bd14d9db 100644 --- a/inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php +++ b/inc/classes/main/file_directories/input/class_FrameworkFileInputPointer.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FrameworkFileInputPointer extends BaseFileIo { +class FrameworkFileInputPointer extends BaseFileIo implements InputPointer { /** * Protected constructor * diff --git a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php index e548fe20..88c565cc 100644 --- a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FrameworkFileInputOutputPointer extends BaseFileIo { +class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputPointer { /** * Protected constructor * diff --git a/inc/classes/main/file_directories/io_handler/class_FileIoStream.php b/inc/classes/main/file_directories/io_handler/class_FileIoStream.php index 35bc0c8b..27ceab32 100644 --- a/inc/classes/main/file_directories/io_handler/class_FileIoStream.php +++ b/inc/classes/main/file_directories/io_handler/class_FileIoStream.php @@ -134,7 +134,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil /** * Reads from a local file * - * @param $fqfn The full-qualified file-name which we shall load + * @param $fqfn The full-qualified file-name which we shall load * @return $array An array with the element 'header' and 'data' * @see FileInputStreamer */ diff --git a/inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php b/inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php index 1af2697b..a3da1856 100644 --- a/inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php +++ b/inc/classes/main/file_directories/output/class_FrameworkFileOutputPointer.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FrameworkFileOutputPointer extends BaseFileIo { +class FrameworkFileOutputPointer extends BaseFileIo implements OutputPointer { /** * Protected constructor * diff --git a/inc/classes/main/iterator/io/class_FileIoIterator.php b/inc/classes/main/iterator/io/class_FileIoIterator.php index 61045519..03c0c25b 100644 --- a/inc/classes/main/iterator/io/class_FileIoIterator.php +++ b/inc/classes/main/iterator/io/class_FileIoIterator.php @@ -45,10 +45,10 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato /** * Creates an instance of this class * - * @param $pointerInstance An instance of a FrameworkFileInputOutputPointer class + * @param $pointerInstance An instance of a InputOutputPointer class * @return $iteratorInstance An instance of a Iterator class */ - public final static function createFileIoIterator (FrameworkFileInputOutputPointer $pointerInstance) { + public final static function createFileIoIterator (InputOutputPointer $pointerInstance) { // Get new instance $iteratorInstance = new FileIoIterator(); diff --git a/inc/classes/middleware/io/class_FileIoHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php index 55f98f8e..81be5056 100644 --- a/inc/classes/middleware/io/class_FileIoHandler.php +++ b/inc/classes/middleware/io/class_FileIoHandler.php @@ -125,9 +125,6 @@ class FileIoHandler extends BaseMiddleware implements IoHandler { * @return void */ public function saveFile ($fileName, $dataStream, FrameworkInterface $objectInstance = NULL) { - // Get output stream - $outInstance = $this->getOutputStream(); - // Default is this array $className = $this->__toString(); @@ -144,7 +141,7 @@ class FileIoHandler extends BaseMiddleware implements IoHandler { ); // Send the fileName and dataArray to the output handler - $outInstance->saveFile($fileName, $dataArray); + $this->getOutputStream()->saveFile($fileName, $dataArray); } /** Loads data from a file over the input handler @@ -153,11 +150,8 @@ class FileIoHandler extends BaseMiddleware implements IoHandler { * @return $array Array with the file contents */ public function loadFileContents ($fqfn) { - // Get output stream - $inInstance = $this->getInputStream(); - // Read from the input handler - return $inInstance->loadFileContents($fqfn); + return $this->getInputStream()->loadFileContents($fqfn); } } -- 2.39.5