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 |
||
19 | class Requirements_Backend |
||
20 | { |
||
21 | use Injectable; |
||
22 | |||
23 | /** |
||
24 | * Whether to add caching query params to the requests for file-based requirements. |
||
25 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
26 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
27 | * while automatically busting this cache every time the file is changed. |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $suffixRequirements = true; |
||
32 | |||
33 | /** |
||
34 | * Whether to combine CSS and JavaScript files |
||
35 | * |
||
36 | * @var bool|null |
||
37 | */ |
||
38 | protected $combinedFilesEnabled = null; |
||
39 | |||
40 | /** |
||
41 | * Determine if files should be combined automatically on dev mode. |
||
42 | * |
||
43 | * By default combined files will not be combined except in test or |
||
44 | * live environments. Turning this on will allow for pre-combining of files in development mode. |
||
45 | * |
||
46 | * @config |
||
47 | * @var bool |
||
48 | */ |
||
49 | private static $combine_in_dev = false; |
||
50 | |||
51 | /** |
||
52 | * Paths to all required JavaScript files relative to docroot |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $javascript = array(); |
||
57 | |||
58 | /** |
||
59 | * Map of included scripts to array of contained files. |
||
60 | * To be used alongside front-end combination mechanisms. |
||
61 | * |
||
62 | * @var array Map of providing filepath => array(provided filepaths) |
||
63 | */ |
||
64 | protected $providedJavascript = array(); |
||
65 | |||
66 | /** |
||
67 | * Paths to all required CSS files relative to the docroot. |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $css = array(); |
||
72 | |||
73 | /** |
||
74 | * All custom javascript code that is inserted into the page's HTML |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $customScript = array(); |
||
79 | |||
80 | /** |
||
81 | * All custom CSS rules which are inserted directly at the bottom of the HTML <head> tag |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | protected $customCSS = array(); |
||
86 | |||
87 | /** |
||
88 | * All custom HTML markup which is added before the closing <head> tag, e.g. additional |
||
89 | * metatags. |
||
90 | * |
||
91 | * @var array |
||
92 | */ |
||
93 | protected $customHeadTags = array(); |
||
94 | |||
95 | /** |
||
96 | * Remembers the file paths or uniquenessIDs of all Requirements cleared through |
||
97 | * {@link clear()}, so that they can be restored later. |
||
98 | * |
||
99 | * @var array |
||
100 | */ |
||
101 | protected $disabled = array(); |
||
102 | |||
103 | /** |
||
104 | * The file paths (relative to docroot) or uniquenessIDs of any included requirements which |
||
105 | * should be blocked when executing {@link inlcudeInHTML()}. This is useful, for example, |
||
106 | * to block scripts included by a superclass without having to override entire functions and |
||
107 | * duplicate a lot of code. |
||
108 | * |
||
109 | * Use {@link unblock()} or {@link unblock_all()} to revert changes. |
||
110 | * |
||
111 | * @var array |
||
112 | */ |
||
113 | protected $blocked = array(); |
||
114 | |||
115 | /** |
||
116 | * A list of combined files registered via {@link combine_files()}. Keys are the output file |
||
117 | * names, values are lists of input files. |
||
118 | * |
||
119 | * @var array |
||
120 | */ |
||
121 | protected $combinedFiles = array(); |
||
122 | |||
123 | /** |
||
124 | * Use the injected minification service to minify any javascript file passed to {@link combine_files()}. |
||
125 | * |
||
126 | * @var bool |
||
127 | */ |
||
128 | protected $minifyCombinedFiles = false; |
||
129 | |||
130 | /** |
||
131 | * Whether or not file headers should be written when combining files |
||
132 | * |
||
133 | * @var boolean |
||
134 | */ |
||
135 | protected $writeHeaderComment = true; |
||
136 | |||
137 | /** |
||
138 | * Where to save combined files. By default they're placed in assets/_combinedfiles, however |
||
139 | * this may be an issue depending on your setup, especially for CSS files which often contain |
||
140 | * relative paths. |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $combinedFilesFolder = null; |
||
145 | |||
146 | /** |
||
147 | * Put all JavaScript includes at the bottom of the template before the closing <body> tag, |
||
148 | * rather than the default behaviour of placing them at the end of the <head> tag. This means |
||
149 | * script downloads won't block other HTTP requests, which can be a performance improvement. |
||
150 | * |
||
151 | * @var bool |
||
152 | */ |
||
153 | public $writeJavascriptToBody = true; |
||
154 | |||
155 | /** |
||
156 | * Force the JavaScript to the bottom of the page, even if there's a script tag in the body already |
||
157 | * |
||
158 | * @var boolean |
||
159 | */ |
||
160 | protected $forceJSToBottom = false; |
||
161 | |||
162 | /** |
||
163 | * Configures the default prefix for combined files. |
||
164 | * |
||
165 | * This defaults to `_combinedfiles`, and is the folder within the configured asset backend that |
||
166 | * combined files will be stored in. If using a backend shared with other systems, it is usually |
||
167 | * necessary to distinguish combined files from other assets. |
||
168 | * |
||
169 | * @config |
||
170 | * @var string |
||
171 | */ |
||
172 | private static $default_combined_files_folder = '_combinedfiles'; |
||
173 | |||
174 | /** |
||
175 | * Flag to include the hash in the querystring instead of the filename for combined files. |
||
176 | * |
||
177 | * By default the `<hash>` of the source files is appended to the end of the combined file |
||
178 | * (prior to the file extension). If combined files are versioned in source control or running |
||
179 | * in a distributed environment (such as one where the newest version of a file may not always be |
||
180 | * immediately available) then it may sometimes be necessary to disable this. When this is set to true, |
||
181 | * the hash will instead be appended via a querystring parameter to enable cache busting, but not in |
||
182 | * the filename itself. I.e. `assets/_combinedfiles/name.js?m=<hash>` |
||
183 | * |
||
184 | * @config |
||
185 | * @var bool |
||
186 | */ |
||
187 | private static $combine_hash_querystring = false; |
||
188 | |||
189 | /** |
||
190 | * @var GeneratedAssetHandler |
||
191 | */ |
||
192 | protected $assetHandler = null; |
||
193 | |||
194 | /** |
||
195 | * @var Requirements_Minifier |
||
196 | */ |
||
197 | protected $minifier = null; |
||
198 | |||
199 | /** |
||
200 | * Gets the backend storage for generated files |
||
201 | * |
||
202 | * @return GeneratedAssetHandler |
||
203 | */ |
||
204 | public function getAssetHandler() |
||
208 | |||
209 | /** |
||
210 | * Set a new asset handler for this backend |
||
211 | * |
||
212 | * @param GeneratedAssetHandler $handler |
||
213 | */ |
||
214 | public function setAssetHandler(GeneratedAssetHandler $handler) |
||
218 | |||
219 | /** |
||
220 | * Gets the minification service for this backend |
||
221 | * |
||
222 | * @deprecated 4.0..5.0 |
||
223 | * @return Requirements_Minifier |
||
224 | */ |
||
225 | public function getMinifier() |
||
229 | |||
230 | /** |
||
231 | * Set a new minification service for this backend |
||
232 | * |
||
233 | * @param Requirements_Minifier $minifier |
||
234 | */ |
||
235 | public function setMinifier(Requirements_Minifier $minifier = null) |
||
239 | |||
240 | /** |
||
241 | * Enable or disable the combination of CSS and JavaScript files |
||
242 | * |
||
243 | * @param bool $enable |
||
244 | */ |
||
245 | public function setCombinedFilesEnabled($enable) |
||
249 | |||
250 | /** |
||
251 | * Check if header comments are written |
||
252 | * |
||
253 | * @return bool |
||
254 | */ |
||
255 | public function getWriteHeaderComment() |
||
259 | |||
260 | /** |
||
261 | * Flag whether header comments should be written for each combined file |
||
262 | * |
||
263 | * @param bool $write |
||
264 | * @return $this |
||
265 | */ |
||
266 | public function setWriteHeaderComment($write) |
||
271 | |||
272 | /** |
||
273 | * Set the folder to save combined files in. By default they're placed in _combinedfiles, |
||
274 | * however this may be an issue depending on your setup, especially for CSS files which often |
||
275 | * contain relative paths. |
||
276 | * |
||
277 | * This must not include any 'assets' prefix |
||
278 | * |
||
279 | * @param string $folder |
||
280 | */ |
||
281 | public function setCombinedFilesFolder($folder) |
||
285 | |||
286 | /** |
||
287 | * Retrieve the combined files folder prefix |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getCombinedFilesFolder() |
||
298 | |||
299 | /** |
||
300 | * Set whether to add caching query params to the requests for file-based requirements. |
||
301 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
302 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
303 | * while automatically busting this cache every time the file is changed. |
||
304 | * |
||
305 | * @param bool |
||
306 | */ |
||
307 | public function setSuffixRequirements($var) |
||
311 | |||
312 | /** |
||
313 | * Check whether we want to suffix requirements |
||
314 | * |
||
315 | * @return bool |
||
316 | */ |
||
317 | public function getSuffixRequirements() |
||
321 | |||
322 | /** |
||
323 | * Set whether you want to write the JS to the body of the page rather than at the end of the |
||
324 | * head tag. |
||
325 | * |
||
326 | * @param bool |
||
327 | * @return $this |
||
328 | */ |
||
329 | public function setWriteJavascriptToBody($var) |
||
334 | |||
335 | /** |
||
336 | * Check whether you want to write the JS to the body of the page rather than at the end of the |
||
337 | * head tag. |
||
338 | * |
||
339 | * @return bool |
||
340 | */ |
||
341 | public function getWriteJavascriptToBody() |
||
345 | |||
346 | /** |
||
347 | * Forces the JavaScript requirements to the end of the body, right before the closing tag |
||
348 | * |
||
349 | * @param bool |
||
350 | * @return $this |
||
351 | */ |
||
352 | public function setForceJSToBottom($var) |
||
357 | |||
358 | /** |
||
359 | * Check if the JavaScript requirements are written to the end of the body, right before the closing tag |
||
360 | * |
||
361 | * @return bool |
||
362 | */ |
||
363 | public function getForceJSToBottom() |
||
367 | |||
368 | /** |
||
369 | * Check if minify files should be combined |
||
370 | * |
||
371 | * @return bool |
||
372 | */ |
||
373 | public function getMinifyCombinedFiles() |
||
377 | |||
378 | /** |
||
379 | * Set if combined files should be minified |
||
380 | * |
||
381 | * @param bool $minify |
||
382 | * @return $this |
||
383 | */ |
||
384 | public function setMinifyCombinedFiles($minify) |
||
389 | |||
390 | /** |
||
391 | * Register the given JavaScript file as required. |
||
392 | * |
||
393 | * @param string $file Relative to docroot |
||
394 | * @param array $options List of options. Available options include: |
||
395 | * - 'provides' : List of scripts files included in this file |
||
396 | * - 'async' : Boolean value to set async attribute to script tag |
||
397 | * - 'defer' : Boolean value to set defer attribute to script tag |
||
398 | * - 'type' : Override script type= value. |
||
399 | */ |
||
400 | public function javascript($file, $options = array()) |
||
439 | |||
440 | /** |
||
441 | * Remove a javascript requirement |
||
442 | * |
||
443 | * @param string $file |
||
444 | */ |
||
445 | protected function unsetJavascript($file) |
||
449 | |||
450 | /** |
||
451 | * Gets all scripts that are already provided by prior scripts. |
||
452 | * This follows these rules: |
||
453 | * - Files will not be considered provided if they are separately |
||
454 | * included prior to the providing file. |
||
455 | * - Providing files can be blocked, and don't provide anything |
||
456 | * - Provided files can't be blocked (you need to block the provider) |
||
457 | * - If a combined file includes files that are provided by prior |
||
458 | * scripts, then these should be excluded from the combined file. |
||
459 | * - If a combined file includes files that are provided by later |
||
460 | * scripts, then these files should be included in the combined |
||
461 | * file, but we can't block the later script either (possible double |
||
462 | * up of file). |
||
463 | * |
||
464 | * @return array Array of provided files (map of $path => $path) |
||
465 | */ |
||
466 | public function getProvidedScripts() |
||
490 | |||
491 | /** |
||
492 | * Returns an array of required JavaScript, excluding blocked |
||
493 | * and duplicates of provided files. |
||
494 | * |
||
495 | * @return array |
||
496 | */ |
||
497 | public function getJavascript() |
||
505 | |||
506 | /** |
||
507 | * Gets all javascript, including blocked files. Unwraps the array into a non-associative list |
||
508 | * |
||
509 | * @return array Indexed array of javascript files |
||
510 | */ |
||
511 | protected function getAllJavascript() |
||
515 | |||
516 | /** |
||
517 | * Register the given JavaScript code into the list of requirements |
||
518 | * |
||
519 | * @param string $script The script content as a string (without enclosing <script> tag) |
||
520 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
521 | */ |
||
522 | public function customScript($script, $uniquenessID = null) |
||
530 | |||
531 | /** |
||
532 | * Return all registered custom scripts |
||
533 | * |
||
534 | * @return array |
||
535 | */ |
||
536 | public function getCustomScripts() |
||
540 | |||
541 | /** |
||
542 | * Register the given CSS styles into the list of requirements |
||
543 | * |
||
544 | * @param string $script CSS selectors as a string (without enclosing <style> tag) |
||
545 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
546 | */ |
||
547 | public function customCSS($script, $uniquenessID = null) |
||
555 | |||
556 | /** |
||
557 | * Return all registered custom CSS |
||
558 | * |
||
559 | * @return array |
||
560 | */ |
||
561 | public function getCustomCSS() |
||
565 | |||
566 | /** |
||
567 | * Add the following custom HTML code to the <head> section of the page |
||
568 | * |
||
569 | * @param string $html Custom HTML code |
||
570 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
571 | */ |
||
572 | public function insertHeadTags($html, $uniquenessID = null) |
||
580 | |||
581 | /** |
||
582 | * Return all custom head tags |
||
583 | * |
||
584 | * @return array |
||
585 | */ |
||
586 | public function getCustomHeadTags() |
||
590 | |||
591 | /** |
||
592 | * Include the content of the given JavaScript file in the list of requirements. Dollar-sign |
||
593 | * variables will be interpolated with values from $vars similar to a .ss template. |
||
594 | * |
||
595 | * @param string $file The template file to load, relative to docroot |
||
596 | * @param string[] $vars The array of variables to interpolate. |
||
597 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
598 | */ |
||
599 | public function javascriptTemplate($file, $vars, $uniquenessID = null) |
||
615 | |||
616 | /** |
||
617 | * Register the given stylesheet into the list of requirements. |
||
618 | * |
||
619 | * @param string $file The CSS file to load, relative to site root |
||
620 | * @param string $media Comma-separated list of media types to use in the link tag |
||
621 | * (e.g. 'screen,projector') |
||
622 | */ |
||
623 | public function css($file, $media = null) |
||
629 | |||
630 | /** |
||
631 | * Remove a css requirement |
||
632 | * |
||
633 | * @param string $file |
||
634 | */ |
||
635 | protected function unsetCSS($file) |
||
639 | |||
640 | /** |
||
641 | * Get the list of registered CSS file requirements, excluding blocked files |
||
642 | * |
||
643 | * @return array Associative array of file to spec |
||
644 | */ |
||
645 | public function getCSS() |
||
649 | |||
650 | /** |
||
651 | * Gets all CSS files requirements, including blocked |
||
652 | * |
||
653 | * @return array Associative array of file to spec |
||
654 | */ |
||
655 | protected function getAllCSS() |
||
659 | |||
660 | /** |
||
661 | * Gets the list of all blocked files |
||
662 | * |
||
663 | * @return array |
||
664 | */ |
||
665 | public function getBlocked() |
||
669 | |||
670 | /** |
||
671 | * Clear either a single or all requirements |
||
672 | * |
||
673 | * Caution: Clearing single rules added via customCSS and customScript only works if you |
||
674 | * originally specified a $uniquenessID. |
||
675 | * |
||
676 | * @param string|int $fileOrID |
||
677 | */ |
||
678 | public function clear($fileOrID = null) |
||
701 | |||
702 | /** |
||
703 | * Restore requirements cleared by call to Requirements::clear |
||
704 | */ |
||
705 | public function restore() |
||
713 | |||
714 | /** |
||
715 | * Block inclusion of a specific file |
||
716 | * |
||
717 | * The difference between this and {@link clear} is that the calling order does not matter; |
||
718 | * {@link clear} must be called after the initial registration, whereas {@link block} can be |
||
719 | * used in advance. This is useful, for example, to block scripts included by a superclass |
||
720 | * without having to override entire functions and duplicate a lot of code. |
||
721 | * |
||
722 | * Note that blocking should be used sparingly because it's hard to trace where an file is |
||
723 | * being blocked from. |
||
724 | * |
||
725 | * @param string|int $fileOrID |
||
726 | */ |
||
727 | public function block($fileOrID) |
||
731 | |||
732 | /** |
||
733 | * Remove an item from the block list |
||
734 | * |
||
735 | * @param string|int $fileOrID |
||
736 | */ |
||
737 | public function unblock($fileOrID) |
||
741 | |||
742 | /** |
||
743 | * Removes all items from the block list |
||
744 | */ |
||
745 | public function unblockAll() |
||
749 | |||
750 | /** |
||
751 | * Update the given HTML content with the appropriate include tags for the registered |
||
752 | * requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, |
||
753 | * including a head and body tag. |
||
754 | * |
||
755 | * @param string $content HTML content that has already been parsed from the $templateFile |
||
756 | * through {@link SSViewer} |
||
757 | * @return string HTML content augmented with the requirements tags |
||
758 | */ |
||
759 | public function includeInHTML($content) |
||
845 | |||
846 | /** |
||
847 | * Given a block of HTML, insert the given scripts at the bottom before |
||
848 | * the closing </body> tag |
||
849 | * |
||
850 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
851 | * @param string $content HTML body |
||
852 | * @return string Merged HTML |
||
853 | */ |
||
854 | protected function insertScriptsAtBottom($jsRequirements, $content) |
||
865 | |||
866 | /** |
||
867 | * Given a block of HTML, insert the given scripts inside the <body></body> |
||
868 | * |
||
869 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
870 | * @param string $content HTML body |
||
871 | * @return string Merged HTML |
||
872 | */ |
||
873 | protected function insertScriptsIntoBody($jsRequirements, $content) |
||
902 | |||
903 | /** |
||
904 | * Given a block of HTML, insert the given code inside the <head></head> block |
||
905 | * |
||
906 | * @param string $jsRequirements String containing one or more html tags |
||
907 | * @param string $content HTML body |
||
908 | * @return string Merged HTML |
||
909 | */ |
||
910 | protected function insertTagsIntoHead($jsRequirements, $content) |
||
919 | |||
920 | /** |
||
921 | * Safely escape a literal string for use in preg_replace replacement |
||
922 | * |
||
923 | * @param string $replacement |
||
924 | * @return string |
||
925 | */ |
||
926 | protected function escapeReplacement($replacement) |
||
930 | |||
931 | /** |
||
932 | * Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given |
||
933 | * HTTP Response |
||
934 | * |
||
935 | * @param HTTPResponse $response |
||
936 | */ |
||
937 | public function includeInResponse(HTTPResponse $response) |
||
966 | |||
967 | /** |
||
968 | * Add i18n files from the given javascript directory. SilverStripe expects that the given |
||
969 | * directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, |
||
970 | * etc. |
||
971 | * |
||
972 | * @param string $langDir The JavaScript lang directory, relative to the site root, e.g., |
||
973 | * 'framework/javascript/lang' |
||
974 | * @param bool $return Return all relative file paths rather than including them in |
||
975 | * requirements |
||
976 | * |
||
977 | * @return array|null All relative files if $return is true, or null otherwise |
||
978 | */ |
||
979 | public function add_i18n_javascript($langDir, $return = false) |
||
1011 | |||
1012 | /** |
||
1013 | * Finds the path for specified file |
||
1014 | * |
||
1015 | * @param string $fileOrUrl |
||
1016 | * @return string|bool |
||
1017 | */ |
||
1018 | protected function pathForFile($fileOrUrl) |
||
1046 | |||
1047 | /** |
||
1048 | * Concatenate several css or javascript files into a single dynamically generated file. This |
||
1049 | * increases performance by fewer HTTP requests. |
||
1050 | * |
||
1051 | * The combined file is regenerated based on every file modification time. Optionally a |
||
1052 | * rebuild can be triggered by appending ?flush=1 to the URL. |
||
1053 | * |
||
1054 | * All combined files will have a comment on the start of each concatenated file denoting their |
||
1055 | * original position. |
||
1056 | * |
||
1057 | * CAUTION: You're responsible for ensuring that the load order for combined files is |
||
1058 | * retained - otherwise combining JavaScript files can lead to functional errors in the |
||
1059 | * JavaScript logic, and combining CSS can lead to incorrect inheritance. You can also |
||
1060 | * only include each file once across all includes and combinations in a single page load. |
||
1061 | * |
||
1062 | * CAUTION: Combining CSS Files discards any "media" information. |
||
1063 | * |
||
1064 | * Example for combined JavaScript: |
||
1065 | * <code> |
||
1066 | * Requirements::combine_files( |
||
1067 | * 'foobar.js', |
||
1068 | * array( |
||
1069 | * 'mysite/javascript/foo.js', |
||
1070 | * 'mysite/javascript/bar.js', |
||
1071 | * ), |
||
1072 | * array( |
||
1073 | * 'async' => true, |
||
1074 | * 'defer' => true, |
||
1075 | * ) |
||
1076 | * ); |
||
1077 | * </code> |
||
1078 | * |
||
1079 | * Example for combined CSS: |
||
1080 | * <code> |
||
1081 | * Requirements::combine_files( |
||
1082 | * 'foobar.css', |
||
1083 | * array( |
||
1084 | * 'mysite/javascript/foo.css', |
||
1085 | * 'mysite/javascript/bar.css', |
||
1086 | * ), |
||
1087 | * array( |
||
1088 | * 'media' => 'print', |
||
1089 | * ) |
||
1090 | * ); |
||
1091 | * </code> |
||
1092 | * |
||
1093 | * @param string $combinedFileName Filename of the combined file relative to docroot |
||
1094 | * @param array $files Array of filenames relative to docroot |
||
1095 | * @param array $options Array of options for combining files. Available options are: |
||
1096 | * - 'media' : If including CSS Files, you can specify a media type |
||
1097 | * - 'async' : If including JavaScript Files, boolean value to set async attribute to script tag |
||
1098 | * - 'defer' : If including JavaScript Files, boolean value to set defer attribute to script tag |
||
1099 | */ |
||
1100 | public function combineFiles($combinedFileName, $files, $options = array()) |
||
1158 | |||
1159 | /** |
||
1160 | * Return path and type of given combined file |
||
1161 | * |
||
1162 | * @param string|array $file Either a file path, or an array spec |
||
1163 | * @return array array with two elements, path and type of file |
||
1164 | */ |
||
1165 | protected function parseCombinedFile($file) |
||
1189 | |||
1190 | /** |
||
1191 | * Return all combined files; keys are the combined file names, values are lists of |
||
1192 | * associative arrays with 'files', 'type', and 'media' keys for details about this |
||
1193 | * combined file. |
||
1194 | * |
||
1195 | * @return array |
||
1196 | */ |
||
1197 | public function getCombinedFiles() |
||
1201 | |||
1202 | /** |
||
1203 | * Includes all combined files, including blocked ones |
||
1204 | * |
||
1205 | * @return array |
||
1206 | */ |
||
1207 | protected function getAllCombinedFiles() |
||
1211 | |||
1212 | /** |
||
1213 | * Clears all combined files |
||
1214 | */ |
||
1215 | public function deleteAllCombinedFiles() |
||
1222 | |||
1223 | /** |
||
1224 | * Clear all registered CSS and JavaScript file combinations |
||
1225 | */ |
||
1226 | public function clearCombinedFiles() |
||
1230 | |||
1231 | /** |
||
1232 | * Do the heavy lifting involved in combining the combined files. |
||
1233 | */ |
||
1234 | public function processCombinedFiles() |
||
1300 | |||
1301 | /** |
||
1302 | * Given a set of files, combine them (as necessary) and return the url |
||
1303 | * |
||
1304 | * @param string $combinedFile Filename for this combined file |
||
1305 | * @param array $fileList List of files to combine |
||
1306 | * @param string $type Either 'js' or 'css' |
||
1307 | * @return string|null URL to this resource, if there are files to combine |
||
1308 | * @throws Exception |
||
1309 | */ |
||
1310 | protected function getCombinedFileURL($combinedFile, $fileList, $type) |
||
1377 | |||
1378 | /** |
||
1379 | * Given a filename and list of files, generate a new filename unique to these files |
||
1380 | * |
||
1381 | * @param string $combinedFile |
||
1382 | * @param array $fileList |
||
1383 | * @return string |
||
1384 | */ |
||
1385 | protected function hashedCombinedFilename($combinedFile, $fileList) |
||
1392 | |||
1393 | /** |
||
1394 | * Check if combined files are enabled |
||
1395 | * |
||
1396 | * @return bool |
||
1397 | */ |
||
1398 | public function getCombinedFilesEnabled() |
||
1412 | |||
1413 | /** |
||
1414 | * For a given filelist, determine some discriminating value to determine if |
||
1415 | * any of these files have changed. |
||
1416 | * |
||
1417 | * @param array $fileList List of files |
||
1418 | * @return string SHA1 bashed file hash |
||
1419 | */ |
||
1420 | protected function hashOfFiles($fileList) |
||
1434 | |||
1435 | /** |
||
1436 | * Registers the given themeable stylesheet as required. |
||
1437 | * |
||
1438 | * A CSS file in the current theme path name 'themename/css/$name.css' is first searched for, |
||
1439 | * and it that doesn't exist and the module parameter is set then a CSS file with that name in |
||
1440 | * the module is used. |
||
1441 | * |
||
1442 | * @param string $name The name of the file - eg '/css/File.css' would have the name 'File' |
||
1443 | * @param string $media Comma-separated list of media types to use in the link tag |
||
1444 | * (e.g. 'screen,projector') |
||
1445 | */ |
||
1446 | public function themedCSS($name, $media = null) |
||
1465 | |||
1466 | /** |
||
1467 | * Registers the given themeable javascript as required. |
||
1468 | * |
||
1469 | * A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for, |
||
1470 | * and it that doesn't exist and the module parameter is set then a javascript file with that name in |
||
1471 | * the module is used. |
||
1472 | * |
||
1473 | * @param string $name The name of the file - eg '/js/File.js' would have the name 'File' |
||
1474 | * @param string $type Comma-separated list of types to use in the script tag |
||
1475 | * (e.g. 'text/javascript,text/ecmascript') |
||
1476 | */ |
||
1477 | public function themedJavascript($name, $type = null) |
||
1500 | |||
1501 | /** |
||
1502 | * Output debugging information. |
||
1503 | */ |
||
1504 | public function debug() |
||
1513 | } |
||
1514 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.