5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseFile extends BaseFrameworkSystem {
26 * Counter for total entries
28 private $totalEntries = 0;
31 * The current file we are working in
33 private $fileName = '';
36 * Protected constructor
38 * @param $className Name of the class
41 protected function __construct ($className) {
42 // Call parent constructor
43 parent::__construct($className);
47 * Destructor for cleaning purposes, etc
51 public final function __destruct() {
52 // Try to close a file
55 // Call the parent destructor
60 * "Getter" for abstracted file size
62 * @return $fileSize Size of abstracted file
64 public function getFileSize () {
65 // Call pointer instanze
66 return $this->getPointerInstance()->getFileSize();
70 * Getter for total entries
72 * @return $totalEntries Total entries in this file
74 public final function getCounter () {
76 return $this->totalEntries;
80 * Setter for total entries
82 * @param $totalEntries Total entries in this file
85 protected final function setCounter ($counter) {
87 $this->totalEntries = $counter;
95 protected final function incrementCounter () {
97 $this->totalEntries++;
101 * Getter for the file pointer
103 * @return $filePointer The file pointer which shall be a valid file resource
104 * @throws UnsupportedOperationException If this method is called
106 public final function getPointer () {
107 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
111 * Setter for file name
113 * @param $fileName The new file name
116 protected final function setFileName ($fileName) {
117 $fileName = (string) $fileName;
118 $this->fileName = $fileName;
122 * Getter for file name
124 * @return $fileName The current file name
126 public final function getFileName () {
127 return $this->fileName;
131 * Close a file source and set it's instance to null and the file name
137 public function closeFile () {
138 $this->partialStub('Unfinished method.');
141 $this->setFileName('');
147 * @return $size Size (in bytes) of file
148 * @todo Handle seekStatus
150 public function size () {
151 // Call pointer instance
152 return $this->getPointerInstance()->size();
156 * Read data a file pointer
158 * @return mixed The result of fread()
159 * @throws NullPointerException If the file pointer instance
160 * is not set by setPointer()
161 * @throws InvalidResourceException If there is being set
163 public function readFromFile () {
164 // Call pointer instance
165 return $this->getPointerInstance()->readFromFile();
169 * Write data to a file pointer
171 * @param $dataStream The data stream we shall write to the file
172 * @return mixed Number of writes bytes or FALSE on error
173 * @throws NullPointerException If the file pointer instance
174 * is not set by setPointer()
175 * @throws InvalidResourceException If there is being set
176 * an invalid file resource
178 public function writeToFile ($dataStream) {
179 // Call pointer instance
180 return $this->getPointerInstance()->writeToFile($dataStream);
184 * Determines whether the EOF has been reached
186 * @return $isEndOfFileReached Whether the EOF has been reached
188 public final function isEndOfFileReached () {
189 // Call pointer instance
190 return $this->getPointerInstance()->isEndOfFileReached();