]> 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 79ce45c9641ca9e5b993cbc45c5760fd48a05907..07524bcabcd83ca3abcfc1b954c368601aa225aa 100644 (file)
@@ -36,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 = 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);
        }