3 namespace Org\Mxchange\CoreFramework\Filesystem\File;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\CloseableFile;
7 use Org\Mxchange\CoreFramework\Filesystem\FilePointer;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
9 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
12 * An abstract file class
14 * @author Roland Haeder <webmaster@ship-simu.org>
16 <<<<<<< HEAD:framework/main/classes/file_directories/class_BaseAbstractFile.php
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
20 >>>>>>> Some updates::inc/main/classes/file_directories/class_BaseAbstractFile.php
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.ship-simu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePointer, CloseableFile {
39 * Counter for total entries
41 private $totalEntries = 0;
44 * Protected constructor
46 * @param $className Name of the class
49 protected function __construct ($className) {
50 // Call parent constructor
51 parent::__construct($className);
55 * Destructor for cleaning purposes, etc
59 public final function __destruct() {
60 // Try to close a file
63 // Call the parent destructor
68 * "Getter" for abstracted file size
70 * @return $fileSize Size of abstracted file
72 public function getFileSize () {
73 // Call pointer instanze
74 return $this->getPointerInstance()->getFileSize();
78 * Getter for total entries
80 * @return $totalEntries Total entries in this file
82 public final function getCounter () {
84 return $this->totalEntries;
88 * Setter for total entries
90 * @param $totalEntries Total entries in this file
93 protected final function setCounter ($counter) {
95 $this->totalEntries = $counter;
103 protected final function incrementCounter () {
105 $this->totalEntries++;
109 * Getter for the file object
111 * @return $fileObject An instance of a SplFileObject
112 * @throws UnsupportedOperationException If this method is called
114 public final function getFileObject () {
115 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
119 * Close a file source and set it's instance to null and the file name
124 public function closeFile () {
126 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
128 // Close down pointer instance as well by unsetting it
129 $this->unsetPointerInstance();
132 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
138 * @return $size Size (in bytes) of file
139 * @todo Handle seekStatus
141 public function size () {
142 // Call pointer instance
143 return $this->getPointerInstance()->size();
147 * Read data a file pointer
149 * @return mixed The result of fread()
150 * @throws NullPointerException If the file pointer instance
151 * is not set by setPointer()
152 * @throws InvalidResourceException If there is being set
154 public function readFromFile () {
155 // Call pointer instance
156 return $this->getPointerInstance()->readFromFile();
160 * Write data to a file pointer
162 * @param $dataStream The data stream we shall write to the file
163 * @return mixed Number of writes bytes or false on error
164 * @throws NullPointerException If the file pointer instance
165 * is not set by setPointer()
166 * @throws InvalidResourceException If there is being set
167 * an invalid file resource
169 public function writeToFile ($dataStream) {
170 // Call pointer instance
171 return $this->getPointerInstance()->writeToFile($dataStream);
175 * Determines whether the EOF has been reached
177 * @return $isEndOfFileReached Whether the EOF has been reached
179 public final function isEndOfFileReached () {
180 // Call pointer instance
181 return $this->getPointerInstance()->isEndOfFileReached();