class_FrameworkFileOutputPointer.php
Go to the documentation of this file.00001 <?php
00024 class FrameworkFileOutputPointer extends BaseFrameworkSystem {
00028 private $fileName = "";
00029
00033 private $filePointer = null;
00034
00038 protected function __construct () {
00039
00040 parent::__construct(__CLASS__);
00041
00042
00043 $this->removeNumberFormaters();
00044 $this->removeSystemArray();
00045 }
00046
00050 public final function __destruct() {
00051
00052 if (is_resource($this->getPointer())) {
00053
00054 $this->closeFile();
00055 }
00056
00057
00058 parent::__destruct();
00059 }
00060
00072 public final static function createFrameworkFileOutputPointer ($fileName, $mode) {
00073
00074 if (is_null($fileName)) {
00075
00076 throw new FileIsEmptyException(null, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00077 }
00078
00079
00080 $filePointer = @fopen($fileName, $mode);
00081 if (($filePointer === null) || ($filePointer === false)) {
00082
00083 throw new FilePointerNotOpenedException ($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
00084 }
00085
00086
00087 $pointerInstance = new FrameworkFileOutputPointer();
00088
00089
00090 $pointerInstance->setPointer($filePointer);
00091 $pointerInstance->setFileName($fileName);
00092
00093
00094 return $pointerInstance;
00095 }
00096
00107 public function writeToFile ($dataStream) {
00108 if (is_null($this->getPointer())) {
00109
00110 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00111 } elseif (!is_resource($this->getPointer())) {
00112
00113 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00114 }
00115
00116
00117 return fwrite($this->getPointer(), $dataStream);
00118 }
00119
00129 public function closeFile () {
00130 if (is_null($this->getPointer())) {
00131
00132 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
00133 } elseif (!is_resource($this->getPointer())) {
00134
00135 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00136 }
00137
00138
00139 @fclose($this->getPointer());
00140 $this->setPointer(null);
00141 $this->setFileName("");
00142 }
00143
00150 public final function setPointer ($filePointer) {
00151
00152 if (is_resource($filePointer) || is_null($filePointer)) {
00153
00154 $this->filePointer = $filePointer;
00155 } else {
00156
00157 throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
00158 }
00159 }
00160
00167 public final function getPointer () {
00168 return $this->filePointer;
00169 }
00170
00177 public final function setFileName ($fileName) {
00178 $fileName = (string) $fileName;
00179 $this->fileName = $fileName;
00180 }
00181
00187 public final function getFileName () {
00188 return $this->fileName;
00189 }
00190 }
00191
00192
00193 ?>