Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/minify/lib/Minify/Cache/File.php
Go to the documentation of this file.
00001 <?php
00007 class Minify_Cache_File {
00008     
00009     public function __construct($path = '', $fileLocking = false)
00010     {
00011         if (! $path) {
00012             require_once 'Solar/Dir.php';
00013             $path = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
00014         }
00015         $this->_locking = $fileLocking;
00016         $this->_path = $path;
00017     }
00018     
00028     public function store($id, $data)
00029     {
00030         $flag = $this->_locking
00031             ? LOCK_EX
00032             : null;
00033         if (is_file($this->_path . '/' . $id)) {
00034             @unlink($this->_path . '/' . $id);
00035         }
00036         if (! @file_put_contents($this->_path . '/' . $id, $data, $flag)) {
00037             return false;
00038         }
00039         // write control
00040         if ($data !== $this->fetch($id)) {
00041             @unlink($file);
00042             return false;
00043         }
00044         return true;
00045     }
00046     
00054     public function getSize($id)
00055     {
00056         return filesize($this->_path . '/' . $id);
00057     }
00058     
00068     public function isValid($id, $srcMtime)
00069     {
00070         $file = $this->_path . '/' . $id;
00071         return (is_file($file) && (filemtime($file) >= $srcMtime));
00072     }
00073     
00079     public function display($id)
00080     {
00081         if ($this->_locking) {
00082             $fp = fopen($this->_path . '/' . $id, 'rb');
00083             flock($fp, LOCK_SH);
00084             fpassthru($fp);
00085             flock($fp, LOCK_UN);
00086             fclose($fp);
00087         } else {
00088             readfile($this->_path . '/' . $id);            
00089         }
00090     }
00091     
00099     public function fetch($id)
00100     {
00101         if ($this->_locking) {
00102             $fp = fopen($this->_path . '/' . $id, 'rb');
00103             flock($fp, LOCK_SH);
00104             $ret = stream_get_contents($fp);
00105             flock($fp, LOCK_UN);
00106             fclose($fp);
00107             return $ret;
00108         } else {
00109             return file_get_contents($this->_path . '/' . $id);
00110         }
00111     }
00112     
00118     public function getPath()
00119     {
00120         return $this->_path;
00121     }
00122     
00123     private $_path = null;
00124     private $_locking = null;
00125 }
 All Data Structures Namespaces Files Functions Variables Enumerations