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