Complex classes like Requirements_Backend often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Requirements_Backend, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Requirements_Backend |
||
22 | { |
||
23 | use Injectable; |
||
24 | |||
25 | /** |
||
26 | * Whether to add caching query params to the requests for file-based requirements. |
||
27 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
28 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
29 | * while automatically busting this cache every time the file is changed. |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $suffixRequirements = true; |
||
34 | |||
35 | /** |
||
36 | * Whether to combine CSS and JavaScript files |
||
37 | * |
||
38 | * @var bool|null |
||
39 | */ |
||
40 | protected $combinedFilesEnabled = null; |
||
41 | |||
42 | /** |
||
43 | * Determine if files should be combined automatically on dev mode. |
||
44 | * |
||
45 | * By default combined files will not be combined except in test or |
||
46 | * live environments. Turning this on will allow for pre-combining of files in development mode. |
||
47 | * |
||
48 | * @config |
||
49 | * @var bool |
||
50 | */ |
||
51 | private static $combine_in_dev = false; |
||
52 | |||
53 | /** |
||
54 | * Paths to all required JavaScript files relative to docroot |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $javascript = array(); |
||
59 | |||
60 | /** |
||
61 | * Map of included scripts to array of contained files. |
||
62 | * To be used alongside front-end combination mechanisms. |
||
63 | * |
||
64 | * @var array Map of providing filepath => array(provided filepaths) |
||
65 | */ |
||
66 | protected $providedJavascript = array(); |
||
67 | |||
68 | /** |
||
69 | * Paths to all required CSS files relative to the docroot. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $css = array(); |
||
74 | |||
75 | /** |
||
76 | * All custom javascript code that is inserted into the page's HTML |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | protected $customScript = array(); |
||
81 | |||
82 | /** |
||
83 | * All custom CSS rules which are inserted directly at the bottom of the HTML <head> tag |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $customCSS = array(); |
||
88 | |||
89 | /** |
||
90 | * All custom HTML markup which is added before the closing <head> tag, e.g. additional |
||
91 | * metatags. |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | protected $customHeadTags = array(); |
||
96 | |||
97 | /** |
||
98 | * Remembers the file paths or uniquenessIDs of all Requirements cleared through |
||
99 | * {@link clear()}, so that they can be restored later. |
||
100 | * |
||
101 | * @var array |
||
102 | */ |
||
103 | protected $disabled = array(); |
||
104 | |||
105 | /** |
||
106 | * The file paths (relative to docroot) or uniquenessIDs of any included requirements which |
||
107 | * should be blocked when executing {@link inlcudeInHTML()}. This is useful, for example, |
||
108 | * to block scripts included by a superclass without having to override entire functions and |
||
109 | * duplicate a lot of code. |
||
110 | * |
||
111 | * Use {@link unblock()} or {@link unblock_all()} to revert changes. |
||
112 | * |
||
113 | * @var array |
||
114 | */ |
||
115 | protected $blocked = array(); |
||
116 | |||
117 | /** |
||
118 | * A list of combined files registered via {@link combine_files()}. Keys are the output file |
||
119 | * names, values are lists of input files. |
||
120 | * |
||
121 | * @var array |
||
122 | */ |
||
123 | protected $combinedFiles = array(); |
||
124 | |||
125 | /** |
||
126 | * Use the injected minification service to minify any javascript file passed to {@link combine_files()}. |
||
127 | * |
||
128 | * @var bool |
||
129 | */ |
||
130 | protected $minifyCombinedFiles = false; |
||
131 | |||
132 | /** |
||
133 | * Whether or not file headers should be written when combining files |
||
134 | * |
||
135 | * @var boolean |
||
136 | */ |
||
137 | protected $writeHeaderComment = true; |
||
138 | |||
139 | /** |
||
140 | * Where to save combined files. By default they're placed in assets/_combinedfiles, however |
||
141 | * this may be an issue depending on your setup, especially for CSS files which often contain |
||
142 | * relative paths. |
||
143 | * |
||
144 | * @var string |
||
145 | */ |
||
146 | protected $combinedFilesFolder = null; |
||
147 | |||
148 | /** |
||
149 | * Put all JavaScript includes at the bottom of the template before the closing <body> tag, |
||
150 | * rather than the default behaviour of placing them at the end of the <head> tag. This means |
||
151 | * script downloads won't block other HTTP requests, which can be a performance improvement. |
||
152 | * |
||
153 | * @var bool |
||
154 | */ |
||
155 | public $writeJavascriptToBody = true; |
||
156 | |||
157 | /** |
||
158 | * Force the JavaScript to the bottom of the page, even if there's a script tag in the body already |
||
159 | * |
||
160 | * @var boolean |
||
161 | */ |
||
162 | protected $forceJSToBottom = false; |
||
163 | |||
164 | /** |
||
165 | * Configures the default prefix for combined files. |
||
166 | * |
||
167 | * This defaults to `_combinedfiles`, and is the folder within the configured asset backend that |
||
168 | * combined files will be stored in. If using a backend shared with other systems, it is usually |
||
169 | * necessary to distinguish combined files from other assets. |
||
170 | * |
||
171 | * @config |
||
172 | * @var string |
||
173 | */ |
||
174 | private static $default_combined_files_folder = '_combinedfiles'; |
||
175 | |||
176 | /** |
||
177 | * Flag to include the hash in the querystring instead of the filename for combined files. |
||
178 | * |
||
179 | * By default the `<hash>` of the source files is appended to the end of the combined file |
||
180 | * (prior to the file extension). If combined files are versioned in source control or running |
||
181 | * in a distributed environment (such as one where the newest version of a file may not always be |
||
182 | * immediately available) then it may sometimes be necessary to disable this. When this is set to true, |
||
183 | * the hash will instead be appended via a querystring parameter to enable cache busting, but not in |
||
184 | * the filename itself. I.e. `assets/_combinedfiles/name.js?m=<hash>` |
||
185 | * |
||
186 | * @config |
||
187 | * @var bool |
||
188 | */ |
||
189 | private static $combine_hash_querystring = false; |
||
190 | |||
191 | /** |
||
192 | * @var GeneratedAssetHandler |
||
193 | */ |
||
194 | protected $assetHandler = null; |
||
195 | |||
196 | /** |
||
197 | * @var Requirements_Minifier |
||
198 | */ |
||
199 | protected $minifier = null; |
||
200 | |||
201 | /** |
||
202 | * Gets the backend storage for generated files |
||
203 | * |
||
204 | * @return GeneratedAssetHandler |
||
205 | */ |
||
206 | public function getAssetHandler() |
||
210 | |||
211 | /** |
||
212 | * Set a new asset handler for this backend |
||
213 | * |
||
214 | * @param GeneratedAssetHandler $handler |
||
215 | */ |
||
216 | public function setAssetHandler(GeneratedAssetHandler $handler) |
||
220 | |||
221 | /** |
||
222 | * Gets the minification service for this backend |
||
223 | * |
||
224 | * @deprecated 4.0..5.0 |
||
225 | * @return Requirements_Minifier |
||
226 | */ |
||
227 | public function getMinifier() |
||
231 | |||
232 | /** |
||
233 | * Set a new minification service for this backend |
||
234 | * |
||
235 | * @param Requirements_Minifier $minifier |
||
236 | */ |
||
237 | public function setMinifier(Requirements_Minifier $minifier = null) |
||
241 | |||
242 | /** |
||
243 | * Enable or disable the combination of CSS and JavaScript files |
||
244 | * |
||
245 | * @param bool $enable |
||
246 | */ |
||
247 | public function setCombinedFilesEnabled($enable) |
||
251 | |||
252 | /** |
||
253 | * Check if header comments are written |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function getWriteHeaderComment() |
||
261 | |||
262 | /** |
||
263 | * Flag whether header comments should be written for each combined file |
||
264 | * |
||
265 | * @param bool $write |
||
266 | * @return $this |
||
267 | */ |
||
268 | public function setWriteHeaderComment($write) |
||
273 | |||
274 | /** |
||
275 | * Set the folder to save combined files in. By default they're placed in _combinedfiles, |
||
276 | * however this may be an issue depending on your setup, especially for CSS files which often |
||
277 | * contain relative paths. |
||
278 | * |
||
279 | * This must not include any 'assets' prefix |
||
280 | * |
||
281 | * @param string $folder |
||
282 | */ |
||
283 | public function setCombinedFilesFolder($folder) |
||
287 | |||
288 | /** |
||
289 | * Retrieve the combined files folder prefix |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function getCombinedFilesFolder() |
||
300 | |||
301 | /* |
||
302 | * Set whether to add caching query params to the requests for file-based requirements. |
||
303 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
304 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
305 | * while automatically busting this cache every time the file is changed. |
||
306 | * |
||
307 | * @param bool |
||
308 | */ |
||
309 | public function setSuffixRequirements($var) |
||
313 | |||
314 | /** |
||
315 | * Check whether we want to suffix requirements |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function getSuffixRequirements() |
||
323 | |||
324 | /** |
||
325 | * Set whether you want to write the JS to the body of the page rather than at the end of the |
||
326 | * head tag. |
||
327 | * |
||
328 | * @param bool |
||
329 | * @return $this |
||
330 | */ |
||
331 | public function setWriteJavascriptToBody($var) |
||
336 | |||
337 | /** |
||
338 | * Check whether you want to write the JS to the body of the page rather than at the end of the |
||
339 | * head tag. |
||
340 | * |
||
341 | * @return bool |
||
342 | */ |
||
343 | public function getWriteJavascriptToBody() |
||
347 | |||
348 | /** |
||
349 | * Forces the JavaScript requirements to the end of the body, right before the closing tag |
||
350 | * |
||
351 | * @param bool |
||
352 | * @return $this |
||
353 | */ |
||
354 | public function setForceJSToBottom($var) |
||
359 | |||
360 | /** |
||
361 | * Check if the JavaScript requirements are written to the end of the body, right before the closing tag |
||
362 | * |
||
363 | * @return bool |
||
364 | */ |
||
365 | public function getForceJSToBottom() |
||
369 | |||
370 | /** |
||
371 | * Check if minify files should be combined |
||
372 | * |
||
373 | * @return bool |
||
374 | */ |
||
375 | public function getMinifyCombinedFiles() |
||
379 | |||
380 | /** |
||
381 | * Set if combined files should be minified |
||
382 | * |
||
383 | * @param bool $minify |
||
384 | * @return $this |
||
385 | */ |
||
386 | public function setMinifyCombinedFiles($minify) |
||
391 | |||
392 | /** |
||
393 | * Register the given JavaScript file as required. |
||
394 | * |
||
395 | * @param string $file Either relative to docroot or in the form "vendor/package:resource" |
||
396 | * @param array $options List of options. Available options include: |
||
397 | * - 'provides' : List of scripts files included in this file |
||
398 | * - 'async' : Boolean value to set async attribute to script tag |
||
399 | * - 'defer' : Boolean value to set defer attribute to script tag |
||
400 | * - 'type' : Override script type= value. |
||
401 | */ |
||
402 | public function javascript($file, $options = array()) |
||
451 | |||
452 | /** |
||
453 | * Remove a javascript requirement |
||
454 | * |
||
455 | * @param string $file |
||
456 | */ |
||
457 | protected function unsetJavascript($file) |
||
461 | |||
462 | /** |
||
463 | * Gets all scripts that are already provided by prior scripts. |
||
464 | * This follows these rules: |
||
465 | * - Files will not be considered provided if they are separately |
||
466 | * included prior to the providing file. |
||
467 | * - Providing files can be blocked, and don't provide anything |
||
468 | * - Provided files can't be blocked (you need to block the provider) |
||
469 | * - If a combined file includes files that are provided by prior |
||
470 | * scripts, then these should be excluded from the combined file. |
||
471 | * - If a combined file includes files that are provided by later |
||
472 | * scripts, then these files should be included in the combined |
||
473 | * file, but we can't block the later script either (possible double |
||
474 | * up of file). |
||
475 | * |
||
476 | * @return array Array of provided files (map of $path => $path) |
||
477 | */ |
||
478 | public function getProvidedScripts() |
||
502 | |||
503 | /** |
||
504 | * Returns an array of required JavaScript, excluding blocked |
||
505 | * and duplicates of provided files. |
||
506 | * |
||
507 | * @return array |
||
508 | */ |
||
509 | public function getJavascript() |
||
517 | |||
518 | /** |
||
519 | * Gets all javascript, including blocked files. Unwraps the array into a non-associative list |
||
520 | * |
||
521 | * @return array Indexed array of javascript files |
||
522 | */ |
||
523 | protected function getAllJavascript() |
||
527 | |||
528 | /** |
||
529 | * Register the given JavaScript code into the list of requirements |
||
530 | * |
||
531 | * @param string $script The script content as a string (without enclosing <script> tag) |
||
532 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
533 | */ |
||
534 | public function customScript($script, $uniquenessID = null) |
||
542 | |||
543 | /** |
||
544 | * Return all registered custom scripts |
||
545 | * |
||
546 | * @return array |
||
547 | */ |
||
548 | public function getCustomScripts() |
||
552 | |||
553 | /** |
||
554 | * Register the given CSS styles into the list of requirements |
||
555 | * |
||
556 | * @param string $script CSS selectors as a string (without enclosing <style> tag) |
||
557 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
558 | */ |
||
559 | public function customCSS($script, $uniquenessID = null) |
||
567 | |||
568 | /** |
||
569 | * Return all registered custom CSS |
||
570 | * |
||
571 | * @return array |
||
572 | */ |
||
573 | public function getCustomCSS() |
||
577 | |||
578 | /** |
||
579 | * Add the following custom HTML code to the <head> section of the page |
||
580 | * |
||
581 | * @param string $html Custom HTML code |
||
582 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
583 | */ |
||
584 | public function insertHeadTags($html, $uniquenessID = null) |
||
592 | |||
593 | /** |
||
594 | * Return all custom head tags |
||
595 | * |
||
596 | * @return array |
||
597 | */ |
||
598 | public function getCustomHeadTags() |
||
602 | |||
603 | /** |
||
604 | * Include the content of the given JavaScript file in the list of requirements. Dollar-sign |
||
605 | * variables will be interpolated with values from $vars similar to a .ss template. |
||
606 | * |
||
607 | * @param string $file The template file to load, relative to docroot |
||
608 | * @param string[] $vars The array of variables to interpolate. |
||
609 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
610 | */ |
||
611 | public function javascriptTemplate($file, $vars, $uniquenessID = null) |
||
627 | |||
628 | /** |
||
629 | * Register the given stylesheet into the list of requirements. |
||
630 | * |
||
631 | * @param string $file The CSS file to load, relative to site root |
||
632 | * @param string $media Comma-separated list of media types to use in the link tag |
||
633 | * (e.g. 'screen,projector') |
||
634 | */ |
||
635 | public function css($file, $media = null) |
||
650 | |||
651 | /** |
||
652 | * Remove a css requirement |
||
653 | * |
||
654 | * @param string $file |
||
655 | */ |
||
656 | protected function unsetCSS($file) |
||
660 | |||
661 | /** |
||
662 | * Get the list of registered CSS file requirements, excluding blocked files |
||
663 | * |
||
664 | * @return array Associative array of file to spec |
||
665 | */ |
||
666 | public function getCSS() |
||
670 | |||
671 | /** |
||
672 | * Gets all CSS files requirements, including blocked |
||
673 | * |
||
674 | * @return array Associative array of file to spec |
||
675 | */ |
||
676 | protected function getAllCSS() |
||
680 | |||
681 | /** |
||
682 | * Gets the list of all blocked files |
||
683 | * |
||
684 | * @return array |
||
685 | */ |
||
686 | public function getBlocked() |
||
690 | |||
691 | /** |
||
692 | * Clear either a single or all requirements |
||
693 | * |
||
694 | * Caution: Clearing single rules added via customCSS and customScript only works if you |
||
695 | * originally specified a $uniquenessID. |
||
696 | * |
||
697 | * @param string|int $fileOrID |
||
698 | */ |
||
699 | public function clear($fileOrID = null) |
||
722 | |||
723 | /** |
||
724 | * Restore requirements cleared by call to Requirements::clear |
||
725 | */ |
||
726 | public function restore() |
||
734 | |||
735 | /** |
||
736 | * Block inclusion of a specific file |
||
737 | * |
||
738 | * The difference between this and {@link clear} is that the calling order does not matter; |
||
739 | * {@link clear} must be called after the initial registration, whereas {@link block} can be |
||
740 | * used in advance. This is useful, for example, to block scripts included by a superclass |
||
741 | * without having to override entire functions and duplicate a lot of code. |
||
742 | * |
||
743 | * Note that blocking should be used sparingly because it's hard to trace where an file is |
||
744 | * being blocked from. |
||
745 | * |
||
746 | * @param string|int $fileOrID |
||
747 | */ |
||
748 | public function block($fileOrID) |
||
752 | |||
753 | /** |
||
754 | * Remove an item from the block list |
||
755 | * |
||
756 | * @param string|int $fileOrID |
||
757 | */ |
||
758 | public function unblock($fileOrID) |
||
762 | |||
763 | /** |
||
764 | * Removes all items from the block list |
||
765 | */ |
||
766 | public function unblockAll() |
||
770 | |||
771 | /** |
||
772 | * Update the given HTML content with the appropriate include tags for the registered |
||
773 | * requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, |
||
774 | * including a head and body tag. |
||
775 | * |
||
776 | * @param string $content HTML content that has already been parsed from the $templateFile |
||
777 | * through {@link SSViewer} |
||
778 | * @return string HTML content augmented with the requirements tags |
||
779 | */ |
||
780 | public function includeInHTML($content) |
||
866 | |||
867 | /** |
||
868 | * Given a block of HTML, insert the given scripts at the bottom before |
||
869 | * the closing </body> tag |
||
870 | * |
||
871 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
872 | * @param string $content HTML body |
||
873 | * @return string Merged HTML |
||
874 | */ |
||
875 | protected function insertScriptsAtBottom($jsRequirements, $content) |
||
886 | |||
887 | /** |
||
888 | * Given a block of HTML, insert the given scripts inside the <body></body> |
||
889 | * |
||
890 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
891 | * @param string $content HTML body |
||
892 | * @return string Merged HTML |
||
893 | */ |
||
894 | protected function insertScriptsIntoBody($jsRequirements, $content) |
||
923 | |||
924 | /** |
||
925 | * Given a block of HTML, insert the given code inside the <head></head> block |
||
926 | * |
||
927 | * @param string $jsRequirements String containing one or more html tags |
||
928 | * @param string $content HTML body |
||
929 | * @return string Merged HTML |
||
930 | */ |
||
931 | protected function insertTagsIntoHead($jsRequirements, $content) |
||
940 | |||
941 | /** |
||
942 | * Safely escape a literal string for use in preg_replace replacement |
||
943 | * |
||
944 | * @param string $replacement |
||
945 | * @return string |
||
946 | */ |
||
947 | protected function escapeReplacement($replacement) |
||
951 | |||
952 | /** |
||
953 | * Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given |
||
954 | * HTTP Response |
||
955 | * |
||
956 | * @param HTTPResponse $response |
||
957 | */ |
||
958 | public function includeInResponse(HTTPResponse $response) |
||
987 | |||
988 | /** |
||
989 | * Add i18n files from the given javascript directory. SilverStripe expects that the given |
||
990 | * directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, |
||
991 | * etc. |
||
992 | * |
||
993 | * @param string $langDir The JavaScript lang directory, relative to the site root, e.g., |
||
994 | * 'framework/javascript/lang' |
||
995 | * @param bool $return Return all relative file paths rather than including them in |
||
996 | * requirements |
||
997 | * |
||
998 | * @return array|null All relative files if $return is true, or null otherwise |
||
999 | */ |
||
1000 | public function add_i18n_javascript($langDir, $return = false) |
||
1032 | |||
1033 | /** |
||
1034 | * Finds the path for specified file |
||
1035 | * |
||
1036 | * @param string $fileOrUrl |
||
1037 | * @return string|bool |
||
1038 | */ |
||
1039 | protected function pathForFile($fileOrUrl) |
||
1048 | |||
1049 | /** |
||
1050 | * Concatenate several css or javascript files into a single dynamically generated file. This |
||
1051 | * increases performance by fewer HTTP requests. |
||
1052 | * |
||
1053 | * The combined file is regenerated based on every file modification time. Optionally a |
||
1054 | * rebuild can be triggered by appending ?flush=1 to the URL. |
||
1055 | * |
||
1056 | * All combined files will have a comment on the start of each concatenated file denoting their |
||
1057 | * original position. |
||
1058 | * |
||
1059 | * CAUTION: You're responsible for ensuring that the load order for combined files is |
||
1060 | * retained - otherwise combining JavaScript files can lead to functional errors in the |
||
1061 | * JavaScript logic, and combining CSS can lead to incorrect inheritance. You can also |
||
1062 | * only include each file once across all includes and combinations in a single page load. |
||
1063 | * |
||
1064 | * CAUTION: Combining CSS Files discards any "media" information. |
||
1065 | * |
||
1066 | * Example for combined JavaScript: |
||
1067 | * <code> |
||
1068 | * Requirements::combine_files( |
||
1069 | * 'foobar.js', |
||
1070 | * array( |
||
1071 | * 'mysite/javascript/foo.js', |
||
1072 | * 'mysite/javascript/bar.js', |
||
1073 | * ), |
||
1074 | * array( |
||
1075 | * 'async' => true, |
||
1076 | * 'defer' => true, |
||
1077 | * ) |
||
1078 | * ); |
||
1079 | * </code> |
||
1080 | * |
||
1081 | * Example for combined CSS: |
||
1082 | * <code> |
||
1083 | * Requirements::combine_files( |
||
1084 | * 'foobar.css', |
||
1085 | * array( |
||
1086 | * 'mysite/javascript/foo.css', |
||
1087 | * 'mysite/javascript/bar.css', |
||
1088 | * ), |
||
1089 | * array( |
||
1090 | * 'media' => 'print', |
||
1091 | * ) |
||
1092 | * ); |
||
1093 | * </code> |
||
1094 | * |
||
1095 | * @param string $combinedFileName Filename of the combined file relative to docroot |
||
1096 | * @param array $files Array of filenames relative to docroot |
||
1097 | * @param array $options Array of options for combining files. Available options are: |
||
1098 | * - 'media' : If including CSS Files, you can specify a media type |
||
1099 | * - 'async' : If including JavaScript Files, boolean value to set async attribute to script tag |
||
1100 | * - 'defer' : If including JavaScript Files, boolean value to set defer attribute to script tag |
||
1101 | */ |
||
1102 | public function combineFiles($combinedFileName, $files, $options = array()) |
||
1160 | |||
1161 | /** |
||
1162 | * Return path and type of given combined file |
||
1163 | * |
||
1164 | * @param string|array $file Either a file path, or an array spec |
||
1165 | * @return array array with two elements, path and type of file |
||
1166 | */ |
||
1167 | protected function parseCombinedFile($file) |
||
1191 | |||
1192 | /** |
||
1193 | * Return all combined files; keys are the combined file names, values are lists of |
||
1194 | * associative arrays with 'files', 'type', and 'media' keys for details about this |
||
1195 | * combined file. |
||
1196 | * |
||
1197 | * @return array |
||
1198 | */ |
||
1199 | public function getCombinedFiles() |
||
1203 | |||
1204 | /** |
||
1205 | * Includes all combined files, including blocked ones |
||
1206 | * |
||
1207 | * @return array |
||
1208 | */ |
||
1209 | protected function getAllCombinedFiles() |
||
1213 | |||
1214 | /** |
||
1215 | * Clears all combined files |
||
1216 | */ |
||
1217 | public function deleteAllCombinedFiles() |
||
1224 | |||
1225 | /** |
||
1226 | * Clear all registered CSS and JavaScript file combinations |
||
1227 | */ |
||
1228 | public function clearCombinedFiles() |
||
1232 | |||
1233 | /** |
||
1234 | * Do the heavy lifting involved in combining the combined files. |
||
1235 | */ |
||
1236 | public function processCombinedFiles() |
||
1302 | |||
1303 | /** |
||
1304 | * Given a set of files, combine them (as necessary) and return the url |
||
1305 | * |
||
1306 | * @param string $combinedFile Filename for this combined file |
||
1307 | * @param array $fileList List of files to combine |
||
1308 | * @param string $type Either 'js' or 'css' |
||
1309 | * @return string|null URL to this resource, if there are files to combine |
||
1310 | * @throws Exception |
||
1311 | */ |
||
1312 | protected function getCombinedFileURL($combinedFile, $fileList, $type) |
||
1379 | |||
1380 | /** |
||
1381 | * Given a filename and list of files, generate a new filename unique to these files |
||
1382 | * |
||
1383 | * @param string $combinedFile |
||
1384 | * @param array $fileList |
||
1385 | * @return string |
||
1386 | */ |
||
1387 | protected function hashedCombinedFilename($combinedFile, $fileList) |
||
1394 | |||
1395 | /** |
||
1396 | * Check if combined files are enabled |
||
1397 | * |
||
1398 | * @return bool |
||
1399 | */ |
||
1400 | public function getCombinedFilesEnabled() |
||
1414 | |||
1415 | /** |
||
1416 | * For a given filelist, determine some discriminating value to determine if |
||
1417 | * any of these files have changed. |
||
1418 | * |
||
1419 | * @param array $fileList List of files |
||
1420 | * @return string SHA1 bashed file hash |
||
1421 | */ |
||
1422 | protected function hashOfFiles($fileList) |
||
1436 | |||
1437 | /** |
||
1438 | * Registers the given themeable stylesheet as required. |
||
1439 | * |
||
1440 | * A CSS file in the current theme path name 'themename/css/$name.css' is first searched for, |
||
1441 | * and it that doesn't exist and the module parameter is set then a CSS file with that name in |
||
1442 | * the module is used. |
||
1443 | * |
||
1444 | * @param string $name The name of the file - eg '/css/File.css' would have the name 'File' |
||
1445 | * @param string $media Comma-separated list of media types to use in the link tag |
||
1446 | * (e.g. 'screen,projector') |
||
1447 | */ |
||
1448 | public function themedCSS($name, $media = null) |
||
1460 | |||
1461 | /** |
||
1462 | * Registers the given themeable javascript as required. |
||
1463 | * |
||
1464 | * A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for, |
||
1465 | * and it that doesn't exist and the module parameter is set then a javascript file with that name in |
||
1466 | * the module is used. |
||
1467 | * |
||
1468 | * @param string $name The name of the file - eg '/js/File.js' would have the name 'File' |
||
1469 | * @param string $type Comma-separated list of types to use in the script tag |
||
1470 | * (e.g. 'text/javascript,text/ecmascript') |
||
1471 | */ |
||
1472 | public function themedJavascript($name, $type = null) |
||
1488 | |||
1489 | /** |
||
1490 | * Output debugging information. |
||
1491 | */ |
||
1492 | public function debug() |
||
1501 | } |
||
1502 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.