*
* @author Roland Haeder <webmaster@ship-simu.org>
* @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
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, CloseableFile {
+abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, CloseableFile {
/**
* Counter for total entries
*/
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
*
* @param $totalEntries Total entries in this file
* @return void
*/
- protected final function setCounter ($counter) {
+ protected final function setCounter (int $counter) {
// Set it
$this->totalEntries = $counter;
}
* 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();
}
/**
*
* @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 () {
* @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
*/
- public function writeToFile ($dataStream) {
+ public function writeToFile (string $dataStream) {
// Call pointer instance
return $this->getPointerInstance()->writeToFile($dataStream);
}