xref: /dokuwiki/inc/Cache/CacheParser.php (revision 2b9be4565f8205c2186c4b537e1fa49846bf2fe9)
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    {
23*2b9be456SAndreas Gohr        global $INPUT;
24*2b9be456SAndreas 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');
32*2b9be456SAndreas 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
430db5771eSMichael Große        if (!file_exists($this->file)) {
440db5771eSMichael Große            return false;
450db5771eSMichael Große        }                   // source exists?
4672c2bae8SMichael Große        return parent::makeDefaultCacheDecision();
470db5771eSMichael Große    }
480db5771eSMichael Große
4942c00b45SMichael Große    protected function addDependencies()
500db5771eSMichael Große    {
510db5771eSMichael Große
520db5771eSMichael Große        // parser cache file dependencies ...
530db5771eSMichael Große        $files = array(
540db5771eSMichael Große            $this->file,                              // ... source
550db5771eSMichael Große            DOKU_INC . 'inc/parser/Parser.php',                // ... parser
560db5771eSMichael Große            DOKU_INC . 'inc/parser/handler.php',               // ... handler
570db5771eSMichael Große        );
580db5771eSMichael Große        $files = array_merge($files, getConfigFiles('main'));    // ... wiki settings
590db5771eSMichael Große
600db5771eSMichael Große        $this->depends['files'] = !empty($this->depends['files']) ?
610db5771eSMichael Große            array_merge($files, $this->depends['files']) :
620db5771eSMichael Große            $files;
6342c00b45SMichael Große        parent::addDependencies();
640db5771eSMichael Große    }
650db5771eSMichael Große
660db5771eSMichael Große}
67