xref: /dokuwiki/inc/Cache/CacheParser.php (revision d4f83172d9533c4d84f450fe22ef630816b21d75)
10db5771eSMichael Große<?php
20db5771eSMichael Große
30db5771eSMichael Großenamespace dokuwiki\Cache;
40db5771eSMichael Große
50db5771eSMichael Große/**
60db5771eSMichael Große * Parser caching
70db5771eSMichael Große */
80db5771eSMichael Großeclass CacheParser extends Cache
90db5771eSMichael Große{
100db5771eSMichael Große    public $file = '';       // source file for cache
110db5771eSMichael Große    public $mode = '';       // input mode (represents the processing the input file will undergo)
120db5771eSMichael Große    public $page = '';
130db5771eSMichael Große
140db5771eSMichael Große    /**
150db5771eSMichael Große     *
160db5771eSMichael Große     * @param string $id page id
170db5771eSMichael Große     * @param string $file source file for cache
180db5771eSMichael Große     * @param string $mode input mode
190db5771eSMichael Große     */
200db5771eSMichael Große    public function __construct($id, $file, $mode)
210db5771eSMichael Große    {
222b9be456SAndreas Gohr        global $INPUT;
232b9be456SAndreas Gohr
240db5771eSMichael Große        if ($id) {
250db5771eSMichael Große            $this->page = $id;
260db5771eSMichael Große        }
270db5771eSMichael Große        $this->file = $file;
280db5771eSMichael Große        $this->mode = $mode;
290db5771eSMichael Große
30c1ec88ceSAndreas Gohr        $this->setEvent('PARSER_CACHE_USE');
312b9be456SAndreas Gohr        parent::__construct($file . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT'), '.' . $mode);
320db5771eSMichael Große    }
330db5771eSMichael Große
340db5771eSMichael Große    /**
350db5771eSMichael Große     * method contains cache use decision logic
360db5771eSMichael Große     *
370db5771eSMichael Große     * @return bool see useCache()
380db5771eSMichael Große     */
3972c2bae8SMichael Große    public function makeDefaultCacheDecision()
400db5771eSMichael Große    {
410db5771eSMichael Große        if (!file_exists($this->file)) {
42*615810c5SAndreas Gohr            // source doesn't exist
430db5771eSMichael Große            return false;
44a95427a5SAndreas Gohr        }
4572c2bae8SMichael Große        return parent::makeDefaultCacheDecision();
460db5771eSMichael Große    }
470db5771eSMichael Große
4842c00b45SMichael Große    protected function addDependencies()
490db5771eSMichael Große    {
500db5771eSMichael Große        // parser cache file dependencies ...
51a95427a5SAndreas Gohr        $files = [
52a95427a5SAndreas Gohr            $this->file, // source
53a95427a5SAndreas Gohr            DOKU_INC . 'inc/Parsing/Parser.php', // parser
54a95427a5SAndreas Gohr            DOKU_INC . 'inc/parser/handler.php', // handler
55a95427a5SAndreas Gohr        ];
56a95427a5SAndreas Gohr        $files = array_merge($files, getConfigFiles('main')); // wiki settings
570db5771eSMichael Große
58a95427a5SAndreas Gohr        $this->depends['files'] = empty($this->depends['files']) ?
59a95427a5SAndreas Gohr            $files :
60a95427a5SAndreas Gohr            array_merge($files, $this->depends['files']);
6142c00b45SMichael Große        parent::addDependencies();
620db5771eSMichael Große    }
630db5771eSMichael Große}
64