class_FrameworkFileInputPointer.php
Go to the documentation of this file.00001 <?php
00024 class FrameworkFileInputPointer extends BaseFrameworkSystem {
00028 private $fileName = "";
00029
00033 private $filePointer = null;
00034
00040 protected function __construct () {
00041
00042 parent::__construct(__CLASS__);
00043
00044
00045 $this->removeNumberFormaters();
00046 $this->removeSystemArray();
00047 }
00048
00054 public final function __destruct() {
00055
00056 if (is_resource($this->getPointer())) {
00057
00058 $this->closeFile();
00059 }
00060
00061
00062 parent::__destruct();
00063 }
00064
00075 public final static function createFrameworkFileInputPointer ($fileName) {
00076
00077 if ((is_null($fileName)) || (empty($fileName))) {
00078
00079 throw new FileIsEmptyException(null, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00080 } elseif (!file_exists($fileName)) {
00081
00082 throw new FileNotFoundException($fileName, self::EXCEPTION_FILE_NOT_FOUND);
00083 } elseif (!is_readable($fileName)) {
00084
00085 throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
00086 }
00087
00088
00089 $filePointer = @fopen($fileName, 'rb');
00090 if ((is_null($filePointer)) || ($filePointer === false)) {
00091
00092 throw new FilePointerNotOpenedException ($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
00093 }
00094
00095
00096 $pointerInstance = new FrameworkFileInputPointer();
00097
00098
00099 $pointerInstance->setPointer($filePointer);
00100 $pointerInstance->setFileName($fileName);
00101
00102
00103 return $pointerInstance;
00104 }
00105
00115 public function readFromFile () {
00116 if (is_null($this->getPointer())) {
00117
00118 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00119 } elseif (!is_resource($this->getPointer())) {
00120
00121 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00122 }
00123
00124
00125 return fread($this->getPointer(), 1024);
00126 }
00127
00137 public function readLinesFromFile () {
00138 if (is_null($this->getPointer())) {
00139
00140 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00141 } elseif (!is_resource($this->getPointer())) {
00142
00143 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00144 }
00145
00146
00147 return fgets($this->getPointer(), 1024);
00148 }
00149
00159 public function closeFile () {
00160 if (is_null($this->getPointer())) {
00161
00162 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00163 } elseif (!is_resource($this->getPointer())) {
00164
00165 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00166 }
00167
00168
00169 @fclose($this->getPointer());
00170 $this->setPointer(null);
00171 $this->setFileName("");
00172 }
00173
00180 public final function setPointer ($filePointer) {
00181
00182 if (is_resource($filePointer) || is_null($filePointer)) {
00183
00184 $this->filePointer = $filePointer;
00185 } else {
00186
00187 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00188 }
00189 }
00190
00197 public final function getPointer () {
00198 return $this->filePointer;
00199 }
00200
00207 public final function setFileName ($fileName) {
00208 $fileName = (string) $fileName;
00209 $this->fileName = $fileName;
00210 }
00211
00217 public final function getFileName () {
00218 return $this->fileName;
00219 }
00220 }
00221
00222
00223 ?>