[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: Clob.php,v 1.6 2004/07/27 23:15:13 hlellelid Exp $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://creole.phpdb.org>. 20 */ 21 22 require_once 'creole/util/Lob.php'; 23 24 /** 25 * A class for handling character (ASCII) LOBs. 26 * 27 * @author Hans Lellelid <hans@xmpl.org> 28 * @version $Revision: 1.6 $ 29 * @package creole.util 30 */ 31 class Clob extends Lob { 32 33 /** 34 * Read LOB data from file. 35 * @param string $file Filename may also be specified here (if not specified using setInputFile()). 36 * @return void 37 * @throws Exception - if no file specified or error on read. 38 * @see setInputFile() 39 */ 40 public function readFromFile($file = null) 41 { 42 if ($file !== null) { 43 $this->setInputFile($file); 44 } 45 if (!$this->inFile) { 46 throw Exception('No file specified for read.'); 47 } 48 $data = null; 49 $file = fopen($this->inFile, "rt"); 50 while (!feof($file)) $data .= fgets($file, 4096); 51 fclose($file); 52 if ($data === false) { 53 throw new Exception('Unable to read from file: '.$this->inFile); 54 } 55 $this->setContents($data); 56 } 57 58 59 /** 60 * Write LOB data to file. 61 * @param string $file Filename may also be specified here (if not set using setOutputFile()). 62 * @throws Exception - if no file specified, no contents to write, or error on write. 63 * @see setOutputFile() 64 */ 65 public function writeToFile($file = null) 66 { 67 if ($file !== null) { 68 $this->setOutputFile($file); 69 } 70 if (!$this->outFile) { 71 throw new Exception('No file specified for write'); 72 } 73 if ($this->data === null) { 74 throw new Exception('No data to write to file'); 75 } 76 $file = fopen($this->inFile, "wt"); 77 if (fputs($file, $this->data) === false) 78 throw new Exception('Unable to write to file: '.$this->outFile); 79 fclose($file); 80 } 81 82 /** 83 * Dump the contents of the file using fpassthru(). 84 * 85 * @return void 86 * @throws Exception if no file or contents. 87 */ 88 function dump() 89 { 90 if (!$this->data) { 91 92 // is there a file name set? 93 if ($this->inFile) { 94 $fp = @fopen($this->inFile, "r"); 95 if (!$fp) { 96 throw new Exception('Unable to open file: '.$this->inFile); 97 } 98 fpassthru($fp); 99 @fclose($fp); 100 } else { 101 throw new Exception('No data to dump'); 102 } 103 104 } else { 105 echo $this->data; 106 } 107 108 } 109 110 111 112 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |