1<?php
2
3namespace dokuwiki\Cache;
4
5/**
6 * Handle the caching of modified (resized/cropped) images
7 */
8class CacheImageMod extends Cache
9{
10    /** @var string source file */
11    protected $file;
12
13    /**
14     * @param string $file Original source file
15     * @param int $w new width in pixel
16     * @param int $h new height in pixel
17     * @param string $ext Image extension - no leading dot
18     * @param bool $crop Is this a crop?
19     */
20    public function __construct($file, $w, $h, $ext, $crop)
21    {
22        $fullext = '.media.' . $w . 'x' . $h;
23        $fullext .= $crop ? '.crop' : '';
24        $fullext .= ".$ext";
25
26        $this->file = $file;
27
28        $this->setEvent('IMAGEMOD_CACHE_USE');
29        parent::__construct($file, $fullext);
30    }
31
32    /** @inheritdoc */
33    public function makeDefaultCacheDecision()
34    {
35        if (!file_exists($this->file)) {
36            return false;
37        }
38        return parent::makeDefaultCacheDecision();
39    }
40
41    /**
42     * Caching depends on the source and the wiki config
43     * @inheritdoc
44     */
45    protected function addDependencies()
46    {
47        parent::addDependencies();
48
49        $this->depends['files'] = array_merge(
50            [$this->file],
51            getConfigFiles('main')
52        );
53    }
54}
55