Lob.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 * $Id: Lob.php,v 1.2 2004/03/29 18:46:46 micha Exp $ 00004 * 00005 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00006 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00007 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00008 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00009 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00010 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00011 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00012 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00013 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00014 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00015 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00016 * 00017 * This software consists of voluntary contributions made by many individuals 00018 * and is licensed under the LGPL. For more information please see 00019 * <http://creole.phpdb.org>. 00020 */ 00021 00022 // 00023 // STATUS: 00024 // - ported: y 00025 // - compiled: y 00026 // - tested: n 00027 // 00028 00036 class Lob { 00037 00044 var /*protected*/ $data; 00045 00050 var /*protected*/ $outFile; 00051 00056 var /*protected*/ $inFile; 00057 00066 var /*private*/ $modified = null; 00067 00073 // public function __construct($data = null) 00074 function Lob($data = null) 00075 { 00076 if ($data !== null) { 00077 $this->setContents($data); 00078 } 00079 } 00080 00086 function getContents() 00087 { 00088 if ($this->data === null && $this->isFromFile()) { 00089 $this->readFromFile(); 00090 } 00091 return $this->data; 00092 } 00093 00101 function setContents($data) 00102 { 00103 $this->data = $data; 00104 00105 if ($this->modified === null) { 00106 // if modified bit hasn't been set yet, 00107 // then it should now be set to FALSE, since 00108 // we just did inital population 00109 $this->modified = false; 00110 } elseif ($this->modified === false) { 00111 // if it was already FALSE, then it should 00112 // now be set to TRUE, since this is a subsequent 00113 // modfiication. 00114 $this->modified = true; 00115 } 00116 } 00117 00125 function dump() 00126 { 00127 trigger_error("Lob::dump(): abstract function has to be reimplemented !", E_USER_ERROR); 00128 } 00129 00135 function setInputFile($filePath) 00136 { 00137 $this->inFile = $filePath; 00138 } 00139 00144 function & getInputFile() 00145 { 00146 return $this->inFile; 00147 } 00148 00154 function setOutputFile($filePath) 00155 { 00156 $this->outFile = $filePath; 00157 } 00158 00163 function & getOutputFile() 00164 { 00165 return $this->outFile; 00166 } 00167 00173 function isFromFile() 00174 { 00175 return ($this->inFile !== null); 00176 } 00177 00187 function & readFromFile($file = null) 00188 { 00189 if ($file !== null) { 00190 $this->setInputFile($file); 00191 } 00192 if (!$this->inFile) { 00193 return new Exception(CREOLE_ERROR, 'No file specified for read.'); 00194 } 00195 $data = @file_get_contents($this->inFile); 00196 if ($data === false) { 00197 return new Exception(CREOLE_ERROR, 'Unable to read from file: '.$this->inFile); 00198 } 00199 $this->setContents($data); 00200 } 00201 00202 00210 function writeToFile($file = null) 00211 { 00212 if ($file !== null) { 00213 $this->setOutputFile($file); 00214 } 00215 if (!$this->outFile) { 00216 return new Exception(CREOLE_ERROR, 'No file specified for write'); 00217 } 00218 if ($this->data === null) { 00219 return new Exception(CREOLE_ERROR, 'No data to write to file'); 00220 } 00221 if (false === @file_put_contents($this->outFile, $this->data)) { 00222 return new Exception(CREOLE_ERROR, 'Unable to write to file: '.$this->outFile); 00223 } 00224 } 00225 00230 function & __toString() 00231 { 00232 return $this->getContents(); 00233 } 00234 00239 function setModified($b) 00240 { 00241 $this->modified = $b; 00242 } 00243 00249 function isModified() 00250 { 00251 // cast it so that NULL will also eval to false 00252 return (boolean) $this->modified; 00253 } 00254 }

This file is part of the Creole[php4] library.


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS