]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/file_directories/class_BaseAbstractFile.php
Continued:
[core.git] / framework / main / classes / file_directories / class_BaseAbstractFile.php
index d9cb807a6b0e81f5048d207e9316e88f9cbde556..ced4f119a6d7c786db8736f62558addffbd8e7db 100644 (file)
@@ -13,11 +13,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
-<<<<<<< HEAD:framework/main/classes/file_directories/class_BaseAbstractFile.php
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
-=======
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
->>>>>>> Some updates::inc/main/classes/file_directories/class_BaseAbstractFile.php
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -40,17 +36,57 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        private $totalEntries = 0;
 
+       /**
+        * An instance of a file I/O pointer class (not handler)
+        */
+       private $pointerInstance = NULL;
+
        /**
         * Protected constructor
         *
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
 
+       /**
+        * Setter for FilePointer instance
+        *
+        * @param       $pointerInstance        An instance of an FilePointer class
+        * @return      void
+        */
+       protected final function setPointerInstance (FilePointer $pointerInstance) {
+               $this->pointerInstance = $pointerInstance;
+       }
+
+       /**
+        * Getter for FilePointer instance
+        *
+        * @return      $pointerInstance        An instance of an FilePointer class
+        */
+       public final function getPointerInstance () {
+               return $this->pointerInstance;
+       }
+
+       /**
+        * Unsets pointer instance which triggers a call of __destruct() if the
+        * instance is still there. This is surely not fatal on already "closed"
+        * file pointer instances.
+        *
+        * I don't want to mess around with above setter by giving it a default
+        * value NULL as setter should always explicitly only set (existing) object
+        * instances and NULL is NULL.
+        *
+        * @return      void
+        */
+       protected final function unsetPointerInstance () {
+               // Simply it to NULL
+               $this->pointerInstance = NULL;
+       }
+
        /**
         * Destructor for cleaning purposes, etc
         *
@@ -90,7 +126,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @param       $totalEntries   Total entries in this file
         * @return      void
         */
-       protected final function setCounter ($counter) {
+       protected final function setCounter (int $counter) {
                // Set it
                $this->totalEntries = $counter;
        }
@@ -109,10 +145,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();
        }
 
        /**
@@ -148,7 +183,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 () {
@@ -162,11 +197,11 @@ 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
         */
-       public function writeToFile ($dataStream) {
+       public function writeToFile (string $dataStream) {
                // Call pointer instance
                return $this->getPointerInstance()->writeToFile($dataStream);
        }