00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 abstract class Lob {
00030
00037 protected $data;
00038
00043 protected $outFile;
00044
00049 protected $inFile;
00050
00059 private $modified = null;
00060
00066 public function __construct($data = null)
00067 {
00068 if ($data !== null) {
00069 $this->setContents($data);
00070 }
00071 }
00072
00078 public function getContents()
00079 {
00080 if ($this->data === null && $this->isFromFile()) {
00081 $this->readFromFile();
00082 }
00083 return $this->data;
00084 }
00085
00093 public function setContents($data)
00094 {
00095 $this->data = $data;
00096
00097 if ($this->modified === null) {
00098
00099
00100
00101 $this->modified = false;
00102 } elseif ($this->modified === false) {
00103
00104
00105
00106 $this->modified = true;
00107 }
00108 }
00109
00117 abstract public function dump();
00118
00124 public function setInputFile($filePath)
00125 {
00126 $this->inFile = $filePath;
00127 }
00128
00133 public function getInputFile()
00134 {
00135 return $this->inFile;
00136 }
00137
00143 public function setOutputFile($filePath)
00144 {
00145 $this->outFile = $filePath;
00146 }
00147
00152 public function getOutputFile()
00153 {
00154 return $this->outFile;
00155 }
00156
00162 public function isFromFile()
00163 {
00164 return ($this->inFile !== null);
00165 }
00166
00176 public function readFromFile($file = null)
00177 {
00178 if ($file !== null) {
00179 $this->setInputFile($file);
00180 }
00181 if (!$this->inFile) {
00182 throw Exception('No file specified for read.');
00183 }
00184 $data = @file_get_contents($this->inFile);
00185 if ($data === false) {
00186 throw new Exception('Unable to read from file: '.$this->inFile);
00187 }
00188 $this->setContents($data);
00189 }
00190
00191
00199 public function writeToFile($file = null)
00200 {
00201 if ($file !== null) {
00202 $this->setOutputFile($file);
00203 }
00204 if (!$this->outFile) {
00205 throw new Exception('No file specified for write');
00206 }
00207 if ($this->data === null) {
00208 throw new Exception('No data to write to file');
00209 }
00210 if (false === @file_put_contents($this->outFile, $this->data)) {
00211 throw new Exception('Unable to write to file: '.$this->outFile);
00212 }
00213 }
00214
00219 public function __toString()
00220 {
00221 return $this->getContents();
00222 }
00223
00228 public function setModified($b)
00229 {
00230 $this->modified = $b;
00231 }
00232
00238 public function isModified()
00239 {
00240
00241 return (boolean) $this->modified;
00242 }
00243 }