1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Plates\Extension\Path; |
4
|
|
|
|
5
|
|
|
use League\Plates; |
6
|
|
|
|
7
|
|
|
final class PathExtension implements Plates\Extension |
8
|
|
|
{ |
9
|
16 |
|
public function register(Plates\Engine $plates) { |
10
|
16 |
|
$c = $plates->getContainer(); |
11
|
16 |
|
$c->add('path.resolvePath.prefixes', function($c) { |
12
|
16 |
|
$config = $c->get('config'); |
13
|
|
|
|
14
|
|
|
// wrap base dir in an array if not already |
15
|
16 |
|
$base_dir = isset($config['base_dir']) ? $config['base_dir'] : null; |
16
|
16 |
|
$base_dir = $base_dir ? (is_string($base_dir) ? [$base_dir] : $base_dir) : $base_dir; |
17
|
16 |
|
return $base_dir; |
18
|
16 |
|
}); |
19
|
16 |
|
$c->addComposed('path.normalizeName', function($c) { |
20
|
|
|
return [ |
21
|
16 |
|
'path.stripExt' => stripExtNormalizeName(), |
22
|
16 |
|
'path.stripPrefix' => stripPrefixNormalizeName($c->get('path.resolvePath.prefixes')) |
23
|
|
|
]; |
24
|
16 |
|
}); |
25
|
16 |
|
$c->addStack('path.resolvePath', function($c) { |
26
|
16 |
|
$config = $c->get('config'); |
27
|
16 |
|
$prefixes = $c->get('path.resolvePath.prefixes'); |
28
|
16 |
|
return array_filter([ |
29
|
16 |
|
'path.id' => idResolvePath(), |
30
|
16 |
|
'path.prefix' => $prefixes ? prefixResolvePath($prefixes, $c->get('fileExists')) : null, |
31
|
16 |
|
'path.ext' => isset($config['ext']) ? extResolvePath($config['ext']) : null, |
32
|
16 |
|
'path.relative' => relativeResolvePath(), |
33
|
|
|
]); |
34
|
16 |
|
}); |
35
|
16 |
|
$plates->defineConfig([ |
|
|
|
|
36
|
|
|
'ext' => 'phtml', |
37
|
16 |
|
'base_dir' => null, |
38
|
16 |
|
]); |
39
|
|
|
$plates->pushComposers(function($c) { |
|
|
|
|
40
|
16 |
|
return [ |
41
|
16 |
|
'path.normalizeName' => normalizeNameCompose($c->get('path.normalizeName')), |
42
|
|
|
'path.resolvePath' => resolvePathCompose($c->get('path.resolvePath')), |
43
|
|
|
]; |
44
|
|
|
}); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: