aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Cache/CacheParser.php
blob: 1273eab31b9de7d5072c61f8a12162303faa026f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace dokuwiki\Cache;

/**
 * Parser caching
 */
class CacheParser extends Cache
{

    public $file = '';       // source file for cache
    public $mode = '';       // input mode (represents the processing the input file will undergo)
    public $page = '';

    /**
     *
     * @param string $id page id
     * @param string $file source file for cache
     * @param string $mode input mode
     */
    public function __construct($id, $file, $mode)
    {
        global $INPUT;

        if ($id) {
            $this->page = $id;
        }
        $this->file = $file;
        $this->mode = $mode;

        $this->setEvent('PARSER_CACHE_USE');
        parent::__construct($file . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT'), '.' . $mode);
    }

    /**
     * method contains cache use decision logic
     *
     * @return bool see useCache()
     */
    public function makeDefaultCacheDecision()
    {
        if (!file_exists($this->file)) {
            // source exists?
            return false;
        }
        return parent::makeDefaultCacheDecision();
    }

    protected function addDependencies()
    {
        // parser cache file dependencies ...
        $files = [
            $this->file, // source
            DOKU_INC . 'inc/Parsing/Parser.php', // parser
            DOKU_INC . 'inc/parser/handler.php', // handler
        ];
        $files = array_merge($files, getConfigFiles('main')); // wiki settings

        $this->depends['files'] = empty($this->depends['files']) ?
            $files :
            array_merge($files, $this->depends['files']);
        parent::addDependencies();
    }

}