151847ece6430075bba4ee9747642377cfb8a1eb
[phancap.git] / src / phancap / Image.php
1 <?php
2 namespace phancap;
3
4 class Image
5 {
6     protected $config;
7     public $name;
8
9
10     public function __construct($name)
11     {
12         $this->name = $name;
13     }
14
15     /**
16      * @return integer Unix timestamp
17      */
18     public function getExpiryDate(Options $options)
19     {
20         $mtime = filemtime($this->getPath());
21
22         return $mtime + $options->values['smaxage'];
23     }
24
25     public function getMimeType()
26     {
27         $ext = substr($this->name, -4);
28         if ($ext == '.jpg') {
29             return 'image/jpeg';
30         } else if ($ext == '.png') {
31             return 'image/png';
32         } else  if ($ext == '.png') {
33             return 'application/pdf';
34         }
35         return 'application/octet-stream';
36     }
37
38     public function getPath()
39     {
40         return $this->config->cacheDir . $this->name;
41     }
42
43     public function getUrl()
44     {
45         return $this->config->cacheDirUrl . $this->name;
46     }
47
48     public function setConfig(Config $config)
49     {
50         $this->config = $config;
51     }
52 }
53 ?>