2058bb6252606c2c0f75b069ddf6a3300205b944
[phancap.git] / src / phancap / Repository.php
1 <?php
2 namespace phancap;
3
4 class Repository
5 {
6     public function setConfig(Config $config)
7     {
8         $this->config = $config;
9     }
10
11     public function getImage(Options $options)
12     {
13         $name = $this->getFilename($options);
14         $img = new Image($name);
15         $img->setConfig($this->config);
16         if (!$this->isAvailable($img)) {
17             $this->render($img, $options);
18         }
19         return $img;
20     }
21
22     public function getFilename(Options $options)
23     {
24         return parse_url($options->values['url'], PHP_URL_HOST)
25             . '-' . md5(\serialize($options->values))
26             . '.' . $options->values['sformat'];
27     }
28
29     public function isAvailable(Image $img)
30     {
31         $path = $img->getPath();
32         if (!file_exists($path)) {
33             return false;
34         }
35         //FIXME: add cache lifetime check
36
37         return true;
38     }
39
40     protected function render(Image $img, Options $options)
41     {
42         $adapter = new Adapter_Cutycapt();
43         $adapter->render($img, $options);
44     }
45 }
46 ?>