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