1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ar_template extends arBase { |
4
|
|
|
private $cache = []; |
5
|
|
|
|
6
|
36 |
|
private function getStorageLayer($path) { |
7
|
36 |
|
global $AR; |
8
|
36 |
|
if (isset($AR->templateStore)) { |
9
|
|
|
$layers = array_keys($AR->templateStore); |
10
|
|
|
// fallback |
11
|
|
|
$layer = array_reduce($layers, function($carry, $item) use ($path) { |
12
|
|
|
if(strpos($path, $item) === 0) { |
13
|
|
|
// item is a prefix of item |
14
|
|
|
if(!isset($carry) || (strlen($carry) < strlen($item) )) { |
15
|
|
|
// item is more specific |
16
|
|
|
$carry = $item; |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
return $carry; |
20
|
|
|
}, null); |
21
|
|
|
if(isset($layer)) { |
22
|
|
|
$config = $AR->templateStore[$layer]; |
23
|
|
|
$classname = 'ar_template_' . $config['driver']; |
24
|
|
|
return new $classname($layer, $config); |
25
|
|
|
} |
26
|
|
|
} |
27
|
36 |
|
return new ar_template_filestore('/',[]); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
12 |
|
public function get($path, $name){ |
31
|
12 |
|
return self::getStorageLayer($path)->get($path, $name); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function save($path, $name, $template, $local=null, $private=null) { |
35
|
|
|
return self::getStorageLayer($path)->save($path, $name, $template, $local, $private); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function load($path, $name) { |
39
|
|
|
return self::getStorageLayer($path)->load($path, $name); |
40
|
|
|
} |
41
|
|
|
|
42
|
60 |
|
public function ls($path) { |
43
|
60 |
|
if (!isset($this->cache[$path])){ |
44
|
28 |
|
$this->cache[$path] = self::getStorageLayer($path)->ls($path); |
45
|
21 |
|
} |
46
|
60 |
|
return $this->cache[$path]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function rm($path, $name){ |
50
|
|
|
return self::getStorageLayer($path)->rm($path, $name); |
51
|
|
|
} |
52
|
|
|
|
53
|
12 |
|
public function exists($path, $name) { |
54
|
12 |
|
return self::getStorageLayer($path)->exists($path, $name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function compile($path, $name) { |
58
|
|
|
return self::getStorageLayer($path)->compile($path, $name); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.