1<?php
2
3namespace dokuwiki\Cache;
4
5/**
6 * Parser caching
7 */
8class CacheParser extends Cache
9{
10    public $file = '';       // source file for cache
11    public $mode = '';       // input mode (represents the processing the input file will undergo)
12    public $page = '';
13
14    /**
15     *
16     * @param string $id page id
17     * @param string $file source file for cache
18     * @param string $mode input mode
19     */
20    public function __construct($id, $file, $mode)
21    {
22        global $INPUT;
23
24        if ($id) {
25            $this->page = $id;
26        }
27        $this->file = $file;
28        $this->mode = $mode;
29
30        $this->setEvent('PARSER_CACHE_USE');
31        parent::__construct($file . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT'), '.' . $mode);
32    }
33
34    /**
35     * method contains cache use decision logic
36     *
37     * @return bool see useCache()
38     */
39    public function makeDefaultCacheDecision()
40    {
41        if (!file_exists($this->file)) {
42            // source doesn't exist
43            return false;
44        }
45        return parent::makeDefaultCacheDecision();
46    }
47
48    protected function addDependencies()
49    {
50        // parser cache file dependencies ...
51        $files = [
52            $this->file, // source
53            DOKU_INC . 'inc/Parsing/Parser.php', // parser
54            DOKU_INC . 'inc/parser/handler.php', // handler
55        ];
56        $files = array_merge($files, getConfigFiles('main')); // wiki settings
57
58        $this->depends['files'] = empty($this->depends['files']) ?
59            $files :
60            array_merge($files, $this->depends['files']);
61        parent::addDependencies();
62    }
63}
64