]> 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 94559b3b3a39788230262fe820e33a7933ff73aa..39694f99903bc9fec28630f714140b77e361b5eb 100644 (file)
@@ -13,7 +13,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -36,6 +36,11 @@ 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
         *
@@ -47,6 +52,41 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
                parent::__construct($className);
        }
 
+       /**
+        * Setter for FilePointer instance
+        *
+        * @param       $pointerInstance        An instance of an FilePointer class
+        * @return      void
+        */
+       protected final function setPointerInstance (FilePointer $pointerInstance = NULL) {
+               $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 invoke setter with no parameter
+               $this->setPointerInstance();
+       }
+
        /**
         * Destructor for cleaning purposes, etc
         *
@@ -77,6 +117,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        public final function getCounter () {
                // Get it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Getting this->totalEntries=%d ... - CALLED!', $this->totalEntries));
                return $this->totalEntries;
        }
 
@@ -86,8 +127,9 @@ 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
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Setting this->totalEntries=%d ... - CALLED!', $counter));
                $this->totalEntries = $counter;
        }
 
@@ -98,7 +140,11 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        protected final function incrementCounter () {
                // Get it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!');
                $this->totalEntries++;
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!');
        }
 
        /**
@@ -110,6 +156,14 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
                return $this->getPointerInstance()->getFileObject();
        }
 
+       /**
+        * Getter for file's name
+        */
+       public final function getFilename () {
+               // Invole file object's method
+               return $this->getFileObject()->getFilename();
+       }
+
        /**
         * Close a file source and set it's instance to null and the file name
         * to empty
@@ -117,14 +171,12 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @return      void
         */
        public function closeFile () {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
                // Close down pointer instance as well by unsetting it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!');
                $this->unsetPointerInstance();
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!');
        }
 
        /**
@@ -161,7 +213,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @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);
        }