xref: /dokuwiki/inc/Cache/CacheParser.php (revision 615810c59cd1bbc7a6f950fa667bd0c75f92d99a)
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
110db5771eSMichael Große    public $file = '';       // source file for cache
120db5771eSMichael Große    public $mode = '';       // input mode (represents the processing the input file will undergo)
130db5771eSMichael Große    public $page = '';
140db5771eSMichael Große
150db5771eSMichael Große    /**
160db5771eSMichael Große     *
170db5771eSMichael Große     * @param string $id page id
180db5771eSMichael Große     * @param string $file source file for cache
190db5771eSMichael Große     * @param string $mode input mode
200db5771eSMichael Große     */
210db5771eSMichael Große    public function __construct($id, $file, $mode)
220db5771eSMichael Große    {
232b9be456SAndreas Gohr        global $INPUT;
242b9be456SAndreas Gohr
250db5771eSMichael Große        if ($id) {
260db5771eSMichael Große            $this->page = $id;
270db5771eSMichael Große        }
280db5771eSMichael Große        $this->file = $file;
290db5771eSMichael Große        $this->mode = $mode;
300db5771eSMichael Große
31c1ec88ceSAndreas Gohr        $this->setEvent('PARSER_CACHE_USE');
322b9be456SAndreas Gohr        parent::__construct($file . $INPUT->server->str('HTTP_HOST') . $INPUT->server->str('SERVER_PORT'), '.' . $mode);
330db5771eSMichael Große    }
340db5771eSMichael Große
350db5771eSMichael Große    /**
360db5771eSMichael Große     * method contains cache use decision logic
370db5771eSMichael Große     *
380db5771eSMichael Große     * @return bool see useCache()
390db5771eSMichael Große     */
4072c2bae8SMichael Große    public function makeDefaultCacheDecision()
410db5771eSMichael Große    {
420db5771eSMichael Große        if (!file_exists($this->file)) {
43*615810c5SAndreas Gohr            // source doesn't exist
440db5771eSMichael Große            return false;
45a95427a5SAndreas Gohr        }
4672c2bae8SMichael Große        return parent::makeDefaultCacheDecision();
470db5771eSMichael Große    }
480db5771eSMichael Große
4942c00b45SMichael Große    protected function addDependencies()
500db5771eSMichael Große    {
510db5771eSMichael Große        // parser cache file dependencies ...
52a95427a5SAndreas Gohr        $files = [
53a95427a5SAndreas Gohr            $this->file, // source
54a95427a5SAndreas Gohr            DOKU_INC . 'inc/Parsing/Parser.php', // parser
55a95427a5SAndreas Gohr            DOKU_INC . 'inc/parser/handler.php', // handler
56a95427a5SAndreas Gohr        ];
57a95427a5SAndreas Gohr        $files = array_merge($files, getConfigFiles('main')); // wiki settings
580db5771eSMichael Große
59a95427a5SAndreas Gohr        $this->depends['files'] = empty($this->depends['files']) ?
60a95427a5SAndreas Gohr            $files :
61a95427a5SAndreas Gohr            array_merge($files, $this->depends['files']);
6242c00b45SMichael Große        parent::addDependencies();
630db5771eSMichael Große    }
640db5771eSMichael Große}
65