X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ffile_directories%2Fclass_BaseAbstractFile.php;h=69b15b06e72c62750a7cef99579a1ed09b66a95b;hb=510a849a26904971bf3f5b58cf7eca73375c6859;hp=7f827a8e0f5af1735fe53d1b33a93f2555dffefa;hpb=c43b569f2b140f40ece9f6e5b9a3825cb76b6413;p=core.git diff --git a/framework/main/classes/file_directories/class_BaseAbstractFile.php b/framework/main/classes/file_directories/class_BaseAbstractFile.php index 7f827a8e..69b15b06 100644 --- a/framework/main/classes/file_directories/class_BaseAbstractFile.php +++ b/framework/main/classes/file_directories/class_BaseAbstractFile.php @@ -1,19 +1,19 @@ * @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 * @@ -30,16 +30,16 @@ use CoreFramework\Object\BaseFrameworkSystem; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, CloseableFile { +abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, CloseableFile { /** * Counter for total entries */ private $totalEntries = 0; /** - * The current file we are working in + * An instance of a file I/O pointer class (not handler) */ - private $fileName = ''; + private $pointerInstance = NULL; /** * Protected constructor @@ -47,11 +47,46 @@ class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, Close * @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 * @@ -107,33 +142,12 @@ class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, Close } /** - * Getter for the file pointer + * Getter for the file object * - * @return $filePointer The file pointer which shall be a valid file resource - * @throws UnsupportedOperationException If this method is called + * @return $fileObject An instance of a SplFileObject */ - public final function getPointer () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for file name - * - * @param $fileName The new file name - * @return void - */ - protected final function setFileName ($fileName) { - $fileName = (string) $fileName; - $this->fileName = $fileName; - } - - /** - * Getter for file name - * - * @return $fileName The current file name - */ - public final function getFileName () { - return $this->fileName; + public final function getFileObject () { + return $this->getPointerInstance()->getFileObject(); } /** @@ -144,14 +158,11 @@ class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, Close */ 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]: CALLED!', __METHOD__, __LINE__)); // Close down pointer instance as well by unsetting it $this->unsetPointerInstance(); - // Remove file name - $this->setFileName(''); - // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__)); } @@ -172,7 +183,7 @@ class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, Close * * @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 () { @@ -186,7 +197,7 @@ class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, Close * @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 */