1 | <?php |
||
10 | class ImageCache |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var string the absolute path to the cache |
||
15 | */ |
||
16 | private $_cachePath; |
||
17 | |||
18 | /** |
||
19 | * @var string the URL to the cache |
||
20 | */ |
||
21 | private $_cacheUrl; |
||
22 | |||
23 | /** |
||
24 | * Class constructor |
||
25 | */ |
||
26 | public function __construct() |
||
27 | { |
||
28 | $this->_cachePath = realpath(Yii::app()->basePath.'/..').'/images/image-cache'; |
||
29 | $this->_cacheUrl = Yii::app()->baseUrl.'/images/image-cache'; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Checks if the given file exists in the cache |
||
34 | * @param string $filename |
||
35 | * @return boolean |
||
36 | */ |
||
37 | public function has($filename) |
||
38 | { |
||
39 | return file_exists($this->_cachePath.DIRECTORY_SEPARATOR.$filename); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Returns the URL to the given file (assuming it is cached) |
||
44 | * @param string $filename |
||
45 | * @return string |
||
46 | */ |
||
47 | public function get($filename) |
||
48 | { |
||
49 | return $this->_cacheUrl.'/'.$filename; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Getter for _cachePath |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getCachePath() |
||
57 | { |
||
58 | return $this->_cachePath; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Getter for _cacheUrl |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getCacheUrl() |
||
68 | } |
||
69 | |||
70 | } |