X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Fclass_BaseFileIo.php;h=ce65bd898a9b8f087af82ffdd4ad13f3fa580295;hp=829557eadb8866c1bbec63d7a25c068c46197da7;hb=b002c5909aa0f781505dde5414964b0f014cde01;hpb=78a010fef84895720e796842208f01dfb619c332 diff --git a/framework/main/classes/file_directories/class_BaseFileIo.php b/framework/main/classes/file_directories/class_BaseFileIo.php index 829557ea..ce65bd89 100644 --- a/framework/main/classes/file_directories/class_BaseFileIo.php +++ b/framework/main/classes/file_directories/class_BaseFileIo.php @@ -1,10 +1,15 @@ . */ -class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFile { +abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFile { /** - * The current file we are working in + * The file object */ - private $fileName = ''; - - /** - * The file pointer - */ - private $filePointer = NULL; + private $fileObject = NULL; /** * Protected constructor @@ -57,7 +57,7 @@ class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFi */ public final function __destruct() { // Is there a resource pointer? Then we have to close the file here! - if (is_resource($this->getPointer())) { + if (is_object($this->getFileObject())) { // Try to close a file $this->closeFile(); } // END - if @@ -72,69 +72,57 @@ class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFi * * @return void * @throws NullPointerException If the file pointer instance is not set by setPointer() - * @throws InvalidResourceException If there is being set + * @throws LogicException If there is no object being set */ public function closeFile () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileObject()->getPathname())); - if (is_null($this->getPointer())) { + if (is_null($this->getFileObject())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_resource($this->getPointer())) { + } elseif (!is_object($this->getFileObject())) { // Pointer is not a valid resource! - throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); + throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject()))); } // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileName())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileObject()->getPathname())); - // Close the file pointer and reset the instance variable - @fclose($this->getPointer()); - $this->setPointer(NULL); - $this->setFileName(''); + // Close the file pointer by NULL-ing it + $this->resetFileObject(); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__)); } /** - * Setter for the file pointer + * Resets file object instance to NULL * - * @param $filePointer File resource * @return void */ - protected final function setPointer ($filePointer) { - $this->filePointer = $filePointer; - } - - /** - * Getter for the file pointer - * - * @return $filePointer The file pointer which shall be a valid file resource - */ - public final function getPointer () { - return $this->filePointer; + protected final function resetFileObject () { + // Set it to NULL + $this->fileObject = NULL; } /** - * Setter for file name + * Setter for the file object * - * @param $fileName The new file name + * @param $fileObject An instance of a SplFileObject class * @return void */ - protected final function setFileName ($fileName) { - $fileName = (string) $fileName; - $this->fileName = $fileName; + protected final function setFileObject (SplFileObject $fileObject) { + $this->fileObject = $fileObject; } /** - * Getter for file name + * Getter for the file object * - * @return $fileName The current file name + * @return $fileObject An instance of a SplFileObject class */ - public final function getFileName () { - return $this->fileName; + public final function getFileObject () { + return $this->fileObject; } /** @@ -143,7 +131,7 @@ class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFi * @return $seekPosition Current seek position */ public final function determineSeekPosition () { - return ftell($this->getPointer()); + return $this->getFileObject()->ftell(); } /** @@ -152,7 +140,7 @@ class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFi * @return $isEndOfFileReached Whether the EOF has been reached */ public final function isEndOfFileReached () { - return feof($this->getPointer()); + return $this->getFileObject()->eof(); } /** @@ -164,7 +152,7 @@ class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFi */ public function seek ($offset, $whence = SEEK_SET) { // Seek to position - $status = fseek($this->getPointer(), $offset, $whence); + $status = $this->getFileObject()->fseek($offset, $whence); // Return status //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] status=%d', __METHOD__, __LINE__, $status));