1 | <?php |
||
8 | class ResourceLoader |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var ResourceLoader |
||
13 | */ |
||
14 | private static $instance; |
||
15 | |||
16 | protected $base; |
||
17 | |||
18 | /** |
||
19 | * List of template "sets" that contain a test manifest, and have an alias. |
||
20 | * E.g. '$default' |
||
21 | * |
||
22 | * @var ThemeList[] |
||
23 | */ |
||
24 | protected $sets = []; |
||
25 | |||
26 | /** |
||
27 | * @return ResourceLoader |
||
28 | */ |
||
29 | public static function inst() |
||
33 | |||
34 | /** |
||
35 | * Set instance |
||
36 | * |
||
37 | * @param ResourceLoader $instance |
||
38 | */ |
||
39 | public static function set_instance(ResourceLoader $instance) |
||
43 | |||
44 | public function __construct($base = null) |
||
48 | |||
49 | /** |
||
50 | * Add a new theme manifest for a given identifier. E.g. '$default' |
||
51 | * |
||
52 | * @param string $set |
||
53 | * @param ThemeList $manifest |
||
54 | */ |
||
55 | public function addSet($set, ThemeList $manifest) |
||
59 | |||
60 | /** |
||
61 | * Get a named theme set |
||
62 | * |
||
63 | * @param string $set |
||
64 | * @return ThemeList |
||
65 | */ |
||
66 | public function getSet($set) |
||
73 | |||
74 | /** |
||
75 | * Returns the absolute path to the given resource. |
||
76 | * |
||
77 | * @param string|array $module 1 or more modules or themes to searrh |
||
78 | * @return string|null The absolute path to the file, if it exists. Returns null if the file can't be found |
||
79 | */ |
||
80 | public function getResourcePath($module, $resource) |
||
87 | |||
88 | /** |
||
89 | * Returns the URL of the given resource. |
||
90 | * |
||
91 | * The URL will be relative to the domain root, unless assets are on a different path (not currently supported but |
||
92 | * may be added in the future. |
||
93 | * |
||
94 | * @param string|array $module A module or list of modules to |
||
95 | * @return string|null The URL of the resource, if it exists |
||
96 | */ |
||
97 | public function getResourceURL($module, $resource) |
||
104 | |||
105 | /** |
||
106 | * Returns the path to the given resource, relative to BASE_PATH |
||
107 | * |
||
108 | * @param string|array $module 1 or more modules or themes to searrh |
||
109 | * @return string|null The absolute path to the file, if it exists. Returns null if the file can't be found |
||
110 | */ |
||
111 | public function getRelativeResourcePath($module, $resource) |
||
129 | |||
130 | /** |
||
131 | * Given a theme identifier, determine the path from the root directory |
||
132 | * |
||
133 | * The mapping from $identifier to path follows these rules: |
||
134 | * - A simple theme name ('mytheme') which maps to the standard themes dir (/themes/mytheme) |
||
135 | * - A theme path with a leading slash ('/mymodule/themes/mytheme') which maps directly to that path. |
||
136 | * - or a vendored theme path. (vendor/mymodule:mytheme) which maps to the nested 'theme' within |
||
137 | * that module. ('/mymodule/themes/mytheme'). |
||
138 | * - A vendored module with no nested theme (vendor/mymodule) which maps to the root directory |
||
139 | * of that module. ('/mymodule'). |
||
140 | * |
||
141 | * @param string $identifier Theme identifier. |
||
142 | * @return string Path from root, not including leading or trailing forward slash. E.g. themes/mytheme |
||
143 | */ |
||
144 | public function getThemePath($identifier) |
||
198 | |||
199 | /** |
||
200 | * Attempts to find possible candidate templates from a set of template |
||
201 | * names from modules, current theme directory and finally the application |
||
202 | * folder. |
||
203 | * |
||
204 | * The template names can be passed in as plain strings, or be in the |
||
205 | * format "type/name", where type is the type of template to search for |
||
206 | * (e.g. Includes, Layout). |
||
207 | * |
||
208 | * @param string|array $template Template name, or template spec in array format with the keys |
||
209 | * 'type' (type string) and 'templates' (template hierarchy in order of precedence). |
||
210 | * If 'templates' is ommitted then any other item in the array will be treated as the template |
||
211 | * list, or list of templates each in the array spec given. |
||
212 | * Templates with an .ss extension will be treated as file paths, and will bypass |
||
213 | * theme-coupled resolution. |
||
214 | * @param array $themes List of themes to use to resolve themes. In most cases |
||
215 | * you should pass in {@see SSViewer::get_themes()} |
||
216 | * @return string Absolute path to resolved template file, or null if not resolved. |
||
217 | * File location will be in the format themes/<theme>/templates/<directories>/<type>/<basename>.ss |
||
218 | * Note that type (e.g. 'Layout') is not the root level directory under 'templates'. |
||
219 | */ |
||
220 | public function findTemplate($template, $themes) |
||
273 | |||
274 | /** |
||
275 | * Resolve all themes to the list of root folders relative to site root |
||
276 | * |
||
277 | * @param array $themes List of themes to resolve. Supports named theme sets. |
||
278 | * @return array List of root-relative folders in order of precendence. |
||
279 | */ |
||
280 | public function getThemePaths($themes) |
||
295 | } |
||
296 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: