1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Plates\Template; |
4
|
|
|
|
5
|
|
|
use League\Plates; |
6
|
|
|
|
7
|
|
|
/** appends a suffix to the name */ |
8
|
|
|
function extResolveName($ext = 'phtml') { |
9
|
|
|
return function($name, array $context) use ($ext) { |
10
|
|
|
return [$name . '.' . $ext, $context]; |
11
|
|
|
}; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
function prefixResolveName($prefix) { |
15
|
|
|
return function($name, array $context) use ($prefix) { |
16
|
|
|
return [ |
17
|
|
|
Plates\Util\joinPath([$prefix, $name]), |
18
|
|
|
$context |
19
|
|
|
]; |
20
|
|
|
}; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** If the template context stores a current directory and */ |
24
|
|
|
function relativeResolveName() { |
25
|
|
|
return function($name, array $context) { |
26
|
|
|
if (strpos($path, './') !== 0 || !isset($context['current_directory'])) { |
|
|
|
|
27
|
|
|
return $name; // nothing to do |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return [ |
31
|
|
|
Plates\Util\joinPath([$context['current_directory'], substr($path, 2)]), |
32
|
|
|
$context |
33
|
|
|
]; |
34
|
|
|
}; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** assumes the template name is in the format of `folder::path`. |
38
|
|
|
folders */ |
39
|
|
|
function folderResolveName(array $folders, $sep = '::') { |
40
|
|
|
return function($name, array $context) use ($folders, $sep) { |
41
|
|
|
if (strpos($name, $sep) === false) { |
42
|
|
|
return [$name, $context]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
list($folder, $path) = explode($sep, $name); |
46
|
|
|
if (!isset($folders[$folder])) { |
47
|
|
|
return [$name, $context]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return [ |
51
|
|
|
Plates\Util\joinPath([$folders[$folder], $path]), |
52
|
|
|
$context |
53
|
|
|
]; |
54
|
|
|
}; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** will automatically*/ |
58
|
|
|
function defaultFolderResolveName(array $folders, $sep = '::') { |
59
|
|
|
return function($name, array $context) use ($folders, $sep) { |
|
|
|
|
60
|
|
|
// if (strpos($name, $sep)) |
61
|
|
|
}; |
62
|
|
|
} |
63
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.