X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Fclass_BaseAbstractFile.php;h=69b15b06e72c62750a7cef99579a1ed09b66a95b;hb=510a849a26904971bf3f5b58cf7eca73375c6859;hp=92b3f114dce1f1ad9b8cf9552ea5d1eb1ecbb921;hpb=b002c5909aa0f781505dde5414964b0f014cde01;p=core.git diff --git a/framework/main/classes/file_directories/class_BaseAbstractFile.php b/framework/main/classes/file_directories/class_BaseAbstractFile.php index 92b3f114..69b15b06 100644 --- a/framework/main/classes/file_directories/class_BaseAbstractFile.php +++ b/framework/main/classes/file_directories/class_BaseAbstractFile.php @@ -13,7 +13,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -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) { + $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 it to NULL + $this->pointerInstance = NULL; + } + /** * Destructor for cleaning purposes, etc * @@ -105,10 +145,9 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * Getter for the file object * * @return $fileObject An instance of a SplFileObject - * @throws UnsupportedOperationException If this method is called */ public final function getFileObject () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + return $this->getPointerInstance()->getFileObject(); } /** @@ -144,7 +183,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * * @return mixed The result of fread() * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set */ public function readFromFile () { @@ -158,7 +197,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * is not set by setFileObject() * @throws InvalidResourceException If there is being set * an invalid file resource */