]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 22 Aug 2025 00:22:29 +0000 (02:22 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 22 Aug 2025 00:22:29 +0000 (02:22 +0200)
- proper type-hints set

framework/main/classes/file_directories/class_BaseAbstractFile.php
framework/main/classes/file_directories/class_BaseFileIo.php
framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php
framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php
framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php
framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php
framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php
framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php
framework/main/interfaces/io/class_FilePointer.php
framework/main/interfaces/io/pointer/class_InputPointer.php
framework/main/interfaces/io/pointer/class_OutputPointer.php

index 51aeaaec51cbc45862336fd7b7e81df56b4589c1..5b3878afe24d0e5d2a8685930a1fd3b93f7b7df2 100644 (file)
@@ -176,6 +176,17 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
                return $this->getPointerInstance()->getFileObject();
        }
 
+       /**
+        * Checks whether a file object is set
+        *
+        * @return      $isset  Whether a file object is set
+        */
+       public final function isFileObjectSet (): bool {
+               // Call pointer instanze
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!');
+               return $this->getPointerInstance()->isFileObjectSet();
+       }
+
        /**
         * Getter for file's name
         *
@@ -222,7 +233,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         *                                                                      is not set by setFileObject()
         * @throws      InvalidResourceException        If there is being set
         */
-       public function readFromFile (): mixed {
+       public function readFromFile (): string {
                // Call pointer instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-ABSTRACT-FILE: CALLED!');
                return $this->getPointerInstance()->readFromFile();
index 35ad9405bb905a759ec380073abd8d70a2c3c47c..9bb48c91aed18748f11100cbec512d93160391a2 100644 (file)
@@ -63,8 +63,8 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         */
        public final function __destruct() {
                // Is there a resource pointer? Then we have to close the file here!
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-FILE-IO: this->fileObject[]=%s - DESTRUCTOR!', gettype($this->getFileObject())));
-               if (is_object($this->getFileObject())) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FILE-IO: DESTRUCTOR!');
+               if ($this->isFileObjectSet()) {
                        // Try to close a file
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-FILE-IO: Invoking this->closeFile() ...');
                        $this->closeFile();
@@ -137,6 +137,15 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
                return $this->fileObject;
        }
 
+       /**
+        * Checks whether a file object is set
+        *
+        * @return      $isset  Whether a file object is set
+        */
+       public final function isFileObjectSet (): bool {
+               return ($this->fileObject instanceof SplFileObject);
+       }
+
        /**
         * Determines seek position
         *
index edbf2ffce96a740127590f3ea6edaadcc5b0fa12..5db3d27c41aec8ca76414fb6a8cb79200ca1c695 100644 (file)
@@ -106,7 +106,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer {
         * @throws      NullPointerException    If the file pointer instance is not set by setFileObject()
         * @throws      LogicException  If there is no object being set
         */
-       public function readFromFile () {
+       public function readFromFile (): string {
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!');
                if (is_null($this->getFileObject())) {
@@ -128,7 +128,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer {
         * @return      $data   Read data from file
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function readLine () {
+       public function readLine (): string {
                // Not supported in binary files ...
                throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
index acfd75ad1c87eb560beb36bfed88e959fc4dc1e1..b66877c191bf850e14a1ccf834a2992fc12ff7ca 100644 (file)
@@ -100,7 +100,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer {
         *
         * @return      $data   Read data from file
         */
-       public function readFromFile () {
+       public function readFromFile (): string {
                // Read 1024 Byte data from the file pointer and return it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!');
                return $this->read(1024);
@@ -111,7 +111,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer {
         *
         * @return      $data   Read data from file
         */
-       public function readLine () {
+       public function readLine (): string {
                // Read whole line from the file pointer and return it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('RAW-FILE-INPUT-POINTER: CALLED!');
                return $this->read();
index 02fa81a08209ef91251224a7d8fa20e789b61b17..71a32b58dde308e51e2433cf60881165ffb23fa7 100644 (file)
@@ -108,7 +108,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         *
         * @return      mixed   The result of fread()
         */
-       public function readFromFile (): mixed {
+       public function readFromFile (): string {
                // Read data from the file pointer and return it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                $data = $this->read(1024);
@@ -222,7 +222,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         *
         * @return      $data   Read data from file
         */
-       public function readLine () {
+       public function readLine (): string {
                // Read whole line
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                $data = $this->read();
index 6517c55c169f6b6d42ce2cd5972feb6578f606a5..74246295eb7c967ef8aa965e1c00b8248122b470 100644 (file)
@@ -98,7 +98,7 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer
         * @throws      NullPointerException    If the file pointer instance is not set by setFileObject()
         * @throws      LogicException  If there is no object being set
         */
-       public function writeToFile (string $dataStream) {
+       public function writeToFile (string $dataStream): mixed {
                // Validate parameter and class own attributes
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('RAW-FILE-OUTPUT-POINTER: dataStream(%d)=%s (trimmed) - CALLED!', strlen($dataStream), trim($dataStream)));
                if (empty($dataStream)) {
@@ -125,7 +125,7 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer
         * @return      void
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function analyzeFileStructure () {
+       public function analyzeFileStructure (): void {
                throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
index 754b5ed2644fc7809ae7da052afb2948c8d9c4e4..ea2d8eb2f2a81c504c311a3d781f8dd0935a0acd 100644 (file)
@@ -95,7 +95,7 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer
         * @throws      NullPointerException    If the file pointer instance is not set by setFileObject()
         * @throws      LogicException  If there is no object being set
         */
-       public function writeToFile (string $dataStream) {
+       public function writeToFile (string $dataStream): mixed {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-OUTPUT-POINTER: dataStream=%s - CALLED!', $dataStream));
                if (empty($dataStream)) {
index b628887ddd5150fdfe10899aabf08aaef4585fc5..0cac7aa6e2369936a8e99a38882e82c58b2e9ffa 100644 (file)
@@ -62,7 +62,8 @@ abstract class BaseInputTextFile extends BaseTextFile {
         *
         * @return      $data   Read data from referenced file
         */
-       public function readLine () {
+       public function readLine (): string {
+               return $this->getPointerInstance()->readLine();
        }
 
 }
index b499371482ea03e4af328709082e17e7216dc9f7..c4fbcecd9c3449f1854032f158ce94ff2b86eac2 100644 (file)
@@ -38,6 +38,13 @@ interface FilePointer extends FrameworkInterface {
         */
        function getFileObject (): SplFileObject;
 
+       /**
+        * Checks whether a file object is set
+        *
+        * @return      $isset  Whether a file object is set
+        */
+       function isFileObjectSet (): bool;
+
        /**
         * Determines whether the EOF has been reached
         *
index 7b2f151432f4bfbe8a4992689b21cab0e5799c25..8c8faf60ee657d9e580befb3c5c70655c52cc8e4 100644 (file)
@@ -34,14 +34,14 @@ interface InputPointer extends StreamableInput, FilePointer {
         *
         * @return      $data   Read data from file
         */
-       function readFromFile ();
+       function readFromFile (): string;
 
        /**
         * Reads a line, maximum 4096 Bytes from current file pointer
         *
         * @return      $data   Read data from file
         */
-       function readLine ();
+       function readLine (): string;
 
        /**
         * Reads given amount of bytes from file.
index 5306c0e17802e4e522b5aefd0b43b47f8c8cc6cd..b05ba8050dd1a06e03c522e6416b92fd1b26f502 100644 (file)
@@ -39,7 +39,7 @@ interface OutputPointer extends StreamableOutput, FilePointer {
         * @throws      InvalidResourceException        If there is being set
         *                                                                                      an invalid file resource
         */
-       function writeToFile (string $dataStream);
+       function writeToFile (string $dataStream): mixed;
 
        /**
         * Writes at given position by seeking to it.