]> git.mxchange.org Git - core.git/commitdiff
InputOutputPointer is the right interface.
authorRoland Haeder <roland@mxchange.org>
Wed, 21 May 2014 19:35:49 +0000 (21:35 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 21 May 2014 19:35:49 +0000 (21:35 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/interfaces/io/pointer/io/class_InputOutputPointer.php
inc/classes/main/file_directories/class_BaseFile.php
inc/classes/main/file_directories/index/class_IndexFile.php
inc/classes/main/file_directories/stack/class_StackFile.php
inc/classes/main/stacker/file/class_BaseFileStack.php

index 6dc483a3df9daece2f98bfb3d425cddf4b8f2755..8daa22c7409c0501fe8b117d96213788f2c2819d 100644 (file)
@@ -28,15 +28,6 @@ interface InputOutputPointer extends InputPointer, OutputPointer {
         * @return      $status         Status of this operation
         */
        function rewind ();
         * @return      $status         Status of this operation
         */
        function rewind ();
-
-       /**
-        * Seeks to given position
-        *
-        * @param       $seekPosition   Seek position in file
-        * @param       $whence                 "Seek mode" (see http://de.php.net/fseek)
-        * @return      $tatus                  Status of this operation
-        */
-       function seek ($seekPosition, $whence = SEEK_SET);
 }
 
 // [EOF]
 }
 
 // [EOF]
index bcc61661bba3d15533f1bbb5c51632daebf1dc7f..a2a3432aa6b3f83f1d729d27bd409b72aaea7ed6 100644 (file)
@@ -51,6 +51,20 @@ class BaseFile extends BaseFrameworkSystem {
                parent::__destruct();
        }
 
                parent::__destruct();
        }
 
+       /**
+        * Initializes this file class
+        *
+        * @param       $fileName       Name of this abstract file
+        * @return      void
+        */
+       protected function initFile ($fileName) {
+               // Get a file i/o pointer instance
+               $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName));
+
+               // ... and set it here
+               $this->setPointerInstance($pointerInstance);
+       }
+
        /**
         * Close a file source and set it's instance to null and the file name
         * to empty
        /**
         * Close a file source and set it's instance to null and the file name
         * to empty
@@ -84,39 +98,6 @@ class BaseFile extends BaseFrameworkSystem {
        public final function getFileName () {
                return $this->fileName;
        }
        public final function getFileName () {
                return $this->fileName;
        }
-
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @todo        0% done
-        */
-       public final function determineSeekPosition () {
-               $this->partialStub('Unfinished method.');
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @todo        0% done
-        */
-       public function seek ($offset, $whence = SEEK_SET) {
-               $this->partialStub('Unfinished method.');
-       }
-
-       /**
-        * Size of this file
-        *
-        * @return      $size   Size (in bytes) of file
-        * @todo        Handle seekStatus
-        * @todo        0% done
-        */
-       public function size () {
-               $this->partialStub('Unfinished method.');
-       }
 }
 
 // [EOF]
 }
 
 // [EOF]
index 2859fd84a0256e8eb7e1d748bd158ae492a3ee81..c65bed4d3757dc3a4a911a7b9a0652e2ff4173dc 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class IndexFile extends BaseFile implements SeekableWritableFileIterator {
+class IndexFile extends BaseFile implements InputOutputPointer {
        /**
         * Protected constructor
         *
        /**
         * Protected constructor
         *
@@ -35,15 +35,97 @@ class IndexFile extends BaseFile implements SeekableWritableFileIterator {
        /**
         * Creates an instance of this File class and prepares it for usage
         *
        /**
         * Creates an instance of this File class and prepares it for usage
         *
+        * @param       $fileName               Name of the index file
         * @return      $fileInstance   An instance of this File class
         */
         * @return      $fileInstance   An instance of this File class
         */
-       public final static function createIndexFile () {
+       public final static function createIndexFile ($fileName) {
                // Get a new instance
                $fileInstance = new IndexFile();
 
                // Get a new instance
                $fileInstance = new IndexFile();
 
+               // Init this abstract file
+               $fileInstance->initFile($fileName);
+
                // Return the prepared instance
                return $fileInstance;
        }
                // Return the prepared instance
                return $fileInstance;
        }
+
+       /**
+        * Determines seek position
+        *
+        * @return      $seekPosition   Current seek position
+        * @todo        0% done
+        */
+       public final function determineSeekPosition () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Seek to given offset (default) or other possibilities as fseek() gives.
+        *
+        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
+        * @param       $whence         Added to offset (default: only use offset to seek to)
+        * @return      $status         Status of file seek: 0 = success, -1 = failed
+        * @todo        0% done
+        */
+       public function seek ($offset, $whence = SEEK_SET) {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Size of this file
+        *
+        * @return      $size   Size (in bytes) of file
+        * @todo        Handle seekStatus
+        * @todo        0% done
+        */
+       public function size () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * 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
+        */
+       public function readFromFile () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Reads given amount of bytes from file.
+        *
+        * @param       $bytes  Amount of bytes to read
+        * @return      $data   Data read from file
+        */
+       public function read ($bytes) {
+               $this->partialStub('bytes=' . $bytes);
+       }
+
+       /**
+        * 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
+        */
+       public function writeToFile ($dataStream) {
+               $this->partialStub('dataStream=' . $dataStream);
+       }
+
+       /**
+        * Rewinds to the beginning of the file
+        *
+        * @return      $status         Status of this operation
+        */
+       public function rewind () {
+               $this->partialStub('Unfinished method.');
+       }
 }
 
 // [EOF]
 }
 
 // [EOF]
index 23ffe84257405215b6e22cb8280103f7f43eae56..138be4918411857ece1db57ffe29c8ed5ab6c856 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class StackFile extends BaseFile implements SeekableWritableFileIterator {
+class StackFile extends BaseFile implements InputOutputPointer {
        /**
         * Protected constructor
         *
        /**
         * Protected constructor
         *
@@ -35,15 +35,97 @@ class StackFile extends BaseFile implements SeekableWritableFileIterator {
        /**
         * Creates an instance of this File class and prepares it for usage
         *
        /**
         * Creates an instance of this File class and prepares it for usage
         *
+        * @param       $fileName               Name of the stack file
         * @return      $fileInstance   An instance of this File class
         */
         * @return      $fileInstance   An instance of this File class
         */
-       public final static function createStackFile () {
+       public final static function createStackFile ($fileName) {
                // Get a new instance
                $fileInstance = new StackFile();
 
                // Get a new instance
                $fileInstance = new StackFile();
 
+               // Init this abstract file
+               $fileInstance->initFile($fileName);
+
                // Return the prepared instance
                return $fileInstance;
        }
                // Return the prepared instance
                return $fileInstance;
        }
+
+       /**
+        * Determines seek position
+        *
+        * @return      $seekPosition   Current seek position
+        * @todo        0% done
+        */
+       public final function determineSeekPosition () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Seek to given offset (default) or other possibilities as fseek() gives.
+        *
+        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
+        * @param       $whence         Added to offset (default: only use offset to seek to)
+        * @return      $status         Status of file seek: 0 = success, -1 = failed
+        * @todo        0% done
+        */
+       public function seek ($offset, $whence = SEEK_SET) {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Size of this file
+        *
+        * @return      $size   Size (in bytes) of file
+        * @todo        Handle seekStatus
+        * @todo        0% done
+        */
+       public function size () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * 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
+        */
+       public function readFromFile () {
+               $this->partialStub('Unfinished method.');
+       }
+
+       /**
+        * Reads given amount of bytes from file.
+        *
+        * @param       $bytes  Amount of bytes to read
+        * @return      $data   Data read from file
+        */
+       public function read ($bytes) {
+               $this->partialStub('bytes=' . $bytes);
+       }
+
+       /**
+        * 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
+        */
+       public function writeToFile ($dataStream) {
+               $this->partialStub('dataStream=' . $dataStream);
+       }
+
+       /**
+        * Rewinds to the beginning of the file
+        *
+        * @return      $status         Status of this operation
+        */
+       public function rewind () {
+               $this->partialStub('Unfinished method.');
+       }
 }
 
 // [EOF]
 }
 
 // [EOF]
index 4729486a5e65a1a749ac2afe0226d369c8affef8..53afecbd50b5aede20952acbc1327a242ad3f141 100644 (file)
@@ -201,7 +201,7 @@ class BaseFileStack extends BaseStacker {
         * @todo        Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file.
         */
        protected function initFileStack ($fileName, $type) {
         * @todo        Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file.
         */
        protected function initFileStack ($fileName, $type) {
-               // Get a file i/o pointer instance for stack file
+               // Get a stack file instance
                $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileName));
 
                // Get iterator instance
                $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileName));
 
                // Get iterator instance