Completed
Push — refactorCachePSR2 ( 42c00b...43ff10 )
by Michael
03:15
created

CacheParser::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Cache;
4
5
/**
6
 * Parser caching
7
 */
8
class 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
    public $_event = 'PARSER_CACHE_USE';
16
17
    /**
18
     *
19
     * @param string $id page id
20
     * @param string $file source file for cache
21
     * @param string $mode input mode
22
     */
23
    public function __construct($id, $file, $mode)
24
    {
25
        if ($id) {
26
            $this->page = $id;
27
        }
28
        $this->file = $file;
29
        $this->mode = $mode;
30
31
        parent::__construct($file . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.' . $mode);
32
    }
33
34
    /**
35
     * method contains cache use decision logic
36
     *
37
     * @return bool               see useCache()
38
     */
39
    public function makeDefaultCacheDecision()
40
    {
41
42
        if (!file_exists($this->file)) {
43
            return false;
44
        }                   // source exists?
45
        return parent::makeDefaultCacheDecision();
46
    }
47
48
    protected function addDependencies()
49
    {
50
51
        // parser cache file dependencies ...
52
        $files = array(
53
            $this->file,                              // ... source
54
            DOKU_INC . 'inc/parser/Parser.php',                // ... parser
55
            DOKU_INC . 'inc/parser/handler.php',               // ... handler
56
        );
57
        $files = array_merge($files, getConfigFiles('main'));    // ... wiki settings
58
59
        $this->depends['files'] = !empty($this->depends['files']) ?
60
            array_merge($files, $this->depends['files']) :
61
            $files;
62
        parent::addDependencies();
63
    }
64
65
}
66