From: Roland Häder Date: Fri, 22 Aug 2025 00:22:29 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f87b11a0a2e5baac70e38825641c119b489eef5;p=core.git Continued: - proper type-hints set --- diff --git a/framework/main/classes/file_directories/class_BaseAbstractFile.php b/framework/main/classes/file_directories/class_BaseAbstractFile.php index 51aeaaec..5b3878af 100644 --- a/framework/main/classes/file_directories/class_BaseAbstractFile.php +++ b/framework/main/classes/file_directories/class_BaseAbstractFile.php @@ -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(); diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index 35ad9405..9bb48c91 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -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 * diff --git a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php index edbf2ffc..5db3d27c 100644 --- a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php +++ b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php @@ -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); } diff --git a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php index acfd75ad..b66877c1 100644 --- a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -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(); diff --git a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php index 02fa81a0..71a32b58 100644 --- a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -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(); diff --git a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php index 6517c55c..74246295 100644 --- a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php @@ -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); } diff --git a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php index 754b5ed2..ea2d8eb2 100644 --- a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php @@ -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)) { diff --git a/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php b/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php index b628887d..0cac7aa6 100644 --- a/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php +++ b/framework/main/classes/file_directories/text/input/class_BaseInputTextFile.php @@ -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(); } } diff --git a/framework/main/interfaces/io/class_FilePointer.php b/framework/main/interfaces/io/class_FilePointer.php index b4993714..c4fbcecd 100644 --- a/framework/main/interfaces/io/class_FilePointer.php +++ b/framework/main/interfaces/io/class_FilePointer.php @@ -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 * diff --git a/framework/main/interfaces/io/pointer/class_InputPointer.php b/framework/main/interfaces/io/pointer/class_InputPointer.php index 7b2f1514..8c8faf60 100644 --- a/framework/main/interfaces/io/pointer/class_InputPointer.php +++ b/framework/main/interfaces/io/pointer/class_InputPointer.php @@ -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. diff --git a/framework/main/interfaces/io/pointer/class_OutputPointer.php b/framework/main/interfaces/io/pointer/class_OutputPointer.php index 5306c0e1..b05ba805 100644 --- a/framework/main/interfaces/io/pointer/class_OutputPointer.php +++ b/framework/main/interfaces/io/pointer/class_OutputPointer.php @@ -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.