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
*
* 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();
*/
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();
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
*
* @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())) {
* @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);
}
*
* @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);
*
* @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();
*
* @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);
*
* @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();
* @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)) {
* @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);
}
* @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)) {
*
* @return $data Read data from referenced file
*/
- public function readLine () {
+ public function readLine (): string {
+ return $this->getPointerInstance()->readLine();
}
}
*/
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
*
*
* @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.
* @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.