1 | <?php |
||
17 | class FileStore |
||
18 | { |
||
19 | protected $root = null; |
||
20 | protected $currentPath = null; |
||
21 | protected $basePath = null; |
||
22 | protected $mode = null; |
||
23 | |||
24 | /** |
||
25 | * @param $root The root directory to store cache images |
||
26 | * @param string $currentPath The path within the root to use |
||
27 | * @param int $mode The filemode to use |
||
28 | */ |
||
29 | 7 | public function __construct($root, $currentPath = '/', $mode = 0770) |
|
36 | |||
37 | /** |
||
38 | * Returns the path for an image based on the current path and the name given |
||
39 | * @param $name The name for the cache image. The name is base64 encoded, so you cannot use full paths, only filenames. |
||
40 | * @return string |
||
41 | */ |
||
42 | 8 | protected function getPath($name) |
|
46 | |||
47 | /** |
||
48 | * Returns the contents for a cached image, if it exists, null otherwise. |
||
49 | * @param string $name |
||
50 | * @return string|null |
||
51 | */ |
||
52 | 5 | public function getVar($name) |
|
59 | |||
60 | /** |
||
61 | * Store a value as a cached image. |
||
62 | * @param string $name |
||
63 | * @param string $value |
||
64 | * @return int |
||
65 | */ |
||
66 | 8 | public function putVar($name, $value) |
|
76 | |||
77 | /** |
||
78 | * Return a fileinfo array (size, ctime, mtime) for a cached image, or null if it isn't found. |
||
79 | * @param $name |
||
80 | * @return array|null |
||
81 | */ |
||
82 | 4 | public function getInfo($name) |
|
95 | |||
96 | /** |
||
97 | * Change the file info, only supports mtime in this implementation. Returns true if the cache image is found. |
||
98 | * @param string $name The name of the cache image |
||
99 | * @param array $info The new file information - an array with 'mtime','size' and/or 'ctime' keys. |
||
100 | * @return bool |
||
101 | */ |
||
102 | 5 | public function setInfo($name, $info) |
|
123 | |||
124 | /** |
||
125 | * Change the path to store/retrieve cache images. |
||
126 | * @param $path |
||
127 | * @return FileStore |
||
128 | */ |
||
129 | 4 | public function cd($path) |
|
133 | |||
134 | /** |
||
135 | * Returns an array with cache image names in the current path. |
||
136 | * @return array |
||
137 | */ |
||
138 | public function ls() |
||
154 | |||
155 | /** |
||
156 | * Remove a cache image. |
||
157 | * @param $name |
||
158 | * @return bool |
||
159 | */ |
||
160 | 2 | public function remove($name) |
|
166 | |||
167 | /** |
||
168 | * @param $dir |
||
169 | */ |
||
170 | 1 | protected function cleanup($dir) |
|
181 | |||
182 | /** |
||
183 | * Removes an entire subtree of cache images. |
||
184 | * @param string $name The name of the image / subdir to remove. |
||
185 | * @return bool |
||
186 | */ |
||
187 | 3 | public function purge($name = '') |
|
199 | |||
200 | /** |
||
201 | * Locks a cache image. Default a write only lock, so you can still read the cache. |
||
202 | * @param string $name |
||
203 | * @param bool $blocking |
||
204 | * @return bool |
||
205 | */ |
||
206 | 2 | public function lock($name, $blocking = false) |
|
221 | |||
222 | /** |
||
223 | * Unlocks a cache image. |
||
224 | * @param $name |
||
225 | * @return bool |
||
226 | */ |
||
227 | 5 | public function unlock($name) |
|
234 | } |
||
235 |