1 | <?php |
||
11 | class ResourceLoader |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var ResourceLoader |
||
16 | */ |
||
17 | private static $instance; |
||
18 | |||
19 | protected $base; |
||
20 | |||
21 | /** |
||
22 | * List of template "sets" that contain a test manifest, and have an alias. |
||
23 | * E.g. '$default' |
||
24 | * |
||
25 | * @var ThemeList[] |
||
26 | */ |
||
27 | protected $sets = []; |
||
28 | |||
29 | /** |
||
30 | * @return ResourceLoader |
||
31 | */ |
||
32 | public static function inst() |
||
36 | |||
37 | /** |
||
38 | * Set instance |
||
39 | * |
||
40 | * @param ResourceLoader $instance |
||
41 | */ |
||
42 | public static function set_instance(ResourceLoader $instance) |
||
46 | |||
47 | public function __construct($base = null) |
||
51 | |||
52 | /** |
||
53 | * Add a new theme manifest for a given identifier. E.g. '$default' |
||
54 | * |
||
55 | * @param string $set |
||
56 | * @param ThemeList $manifest |
||
57 | */ |
||
58 | public function addSet($set, ThemeList $manifest) |
||
62 | |||
63 | /** |
||
64 | * Get a named theme set |
||
65 | * |
||
66 | * @param string $set |
||
67 | * @return ThemeList |
||
68 | */ |
||
69 | public function getSet($set) |
||
76 | |||
77 | /** |
||
78 | * Returns the absolute path to the given resource. |
||
79 | * |
||
80 | * @param string|array $module 1 or more modules or themes to searrh |
||
81 | * @return string|null The absolute path to the file, if it exists. Returns null if the file can't be found |
||
82 | */ |
||
83 | public function getResourcePath($module, $resource) |
||
90 | |||
91 | /** |
||
92 | * Returns the URL of the given resource. |
||
93 | * |
||
94 | * The URL will be relative to the domain root, unless assets are on a different path (not currently supported but |
||
95 | * may be added in the future. |
||
96 | * |
||
97 | * @param string|array $module A module or list of modules to |
||
98 | * @return string|null The URL of the resource, if it exists |
||
99 | */ |
||
100 | public function getResourceURL($module, $resource) |
||
107 | |||
108 | /** |
||
109 | * Returns the path to the given resource, relative to BASE_PATH |
||
110 | * |
||
111 | * @param string|array $module 1 or more modules or themes to searrh |
||
112 | * @return string|null The absolute path to the file, if it exists. Returns null if the file can't be found |
||
113 | */ |
||
114 | public function getRelativeResourcePath($module, $resource) |
||
132 | |||
133 | /** |
||
134 | * Given a theme identifier, determine the path from the root directory |
||
135 | * |
||
136 | * The mapping from $identifier to path follows these rules: |
||
137 | * - A simple theme name ('mytheme') which maps to the standard themes dir (/themes/mytheme) |
||
138 | * - A theme path with a leading slash ('/mymodule/themes/mytheme') which maps directly to that path. |
||
139 | * - or a vendored theme path. (vendor/mymodule:mytheme) which maps to the nested 'theme' within |
||
140 | * that module. ('/mymodule/themes/mytheme'). |
||
141 | * - A vendored module with no nested theme (vendor/mymodule) which maps to the root directory |
||
142 | * of that module. ('/mymodule'). |
||
143 | * |
||
144 | * @param string $identifier Theme identifier. |
||
145 | * @return string Path from root, not including leading or trailing forward slash. E.g. themes/mytheme |
||
146 | */ |
||
147 | public function getThemePath($identifier) |
||
201 | |||
202 | /** |
||
203 | * Attempts to find possible candidate templates from a set of template |
||
204 | * names from modules, current theme directory and finally the application |
||
205 | * folder. |
||
206 | * |
||
207 | * The template names can be passed in as plain strings, or be in the |
||
208 | * format "type/name", where type is the type of template to search for |
||
209 | * (e.g. Includes, Layout). |
||
210 | * |
||
211 | * @param string|array $template Template name, or template spec in array format with the keys |
||
212 | * 'type' (type string) and 'templates' (template hierarchy in order of precedence). |
||
213 | * If 'templates' is ommitted then any other item in the array will be treated as the template |
||
214 | * list, or list of templates each in the array spec given. |
||
215 | * Templates with an .ss extension will be treated as file paths, and will bypass |
||
216 | * theme-coupled resolution. |
||
217 | * @param array $themes List of themes to use to resolve themes. In most cases |
||
218 | * you should pass in {@see SSViewer::get_themes()} |
||
219 | * @return string Absolute path to resolved template file, or null if not resolved. |
||
220 | * File location will be in the format themes/<theme>/templates/<directories>/<type>/<basename>.ss |
||
221 | * Note that type (e.g. 'Layout') is not the root level directory under 'templates'. |
||
222 | */ |
||
223 | public function findTemplate($template, $themes) |
||
276 | |||
277 | /** |
||
278 | * Resolve all themes to the list of root folders relative to site root |
||
279 | * |
||
280 | * @param array $themes List of themes to resolve. Supports named theme sets. |
||
281 | * @return array List of root-relative folders in order of precendence. |
||
282 | */ |
||
283 | public function getThemePaths($themes) |
||
298 | } |
||
299 |
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: