HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/extras/FSTools/File.php
Go to the documentation of this file.
00001 <?php
00002 
00010 class FSTools_File
00011 {
00012 
00014     protected $name;
00015 
00017     protected $handle = false;
00018 
00020     protected $fs;
00021 
00026     public function __construct($name, $fs = false) {
00027         $this->name = $name;
00028         $this->fs = $fs ? $fs : FSTools::singleton();
00029     }
00030 
00032     public function getName() {return $this->name;}
00033 
00035     public function getDirectory() {return $this->fs->dirname($this->name);}
00036 
00041     public function get() {
00042         return $this->fs->file_get_contents($this->name);
00043     }
00044 
00046     public function write($contents) {
00047         return $this->fs->file_put_contents($this->name, $contents);
00048     }
00049 
00051     public function delete() {
00052         return $this->fs->unlink($this->name);
00053     }
00054 
00056     public function exists() {
00057         return $this->fs->is_file($this->name);
00058     }
00059 
00061     public function getMTime() {
00062         return $this->fs->filemtime($this->name);
00063     }
00064 
00070     public function chmod($octal_code) {
00071         return @$this->fs->chmod($this->name, $octal_code);
00072     }
00073 
00075     public function open($mode) {
00076         if ($this->handle) $this->close();
00077         $this->handle = $this->fs->fopen($this->name, $mode);
00078         return true;
00079     }
00080 
00082     public function close() {
00083         if (!$this->handle) return false;
00084         $status = $this->fs->fclose($this->handle);
00085         $this->handle = false;
00086         return $status;
00087     }
00088 
00090     public function getLine($length = null) {
00091         if (!$this->handle) $this->open('r');
00092         if ($length === null) return $this->fs->fgets($this->handle);
00093         else return $this->fs->fgets($this->handle, $length);
00094     }
00095 
00097     public function getChar() {
00098         if (!$this->handle) $this->open('r');
00099         return $this->fs->fgetc($this->handle);
00100     }
00101 
00103     public function read($length) {
00104         if (!$this->handle) $this->open('r');
00105         return $this->fs->fread($this->handle, $length);
00106     }
00107 
00109     public function put($string) {
00110         if (!$this->handle) $this->open('a');
00111         return $this->fs->fwrite($this->handle, $string);
00112     }
00113 
00115     public function eof() {
00116         if (!$this->handle) return true;
00117         return $this->fs->feof($this->handle);
00118     }
00119 
00120     public function __destruct() {
00121         if ($this->handle) $this->close();
00122     }
00123 
00124 }
00125 
00126 // vim: et sw=4 sts=4