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()) |
||
443 | |||
444 | /** |
||
445 | * Remove a javascript requirement |
||
446 | * |
||
447 | * @param string $file |
||
448 | */ |
||
449 | protected function unsetJavascript($file) |
||
453 | |||
454 | /** |
||
455 | * Gets all scripts that are already provided by prior scripts. |
||
456 | * This follows these rules: |
||
457 | * - Files will not be considered provided if they are separately |
||
458 | * included prior to the providing file. |
||
459 | * - Providing files can be blocked, and don't provide anything |
||
460 | * - Provided files can't be blocked (you need to block the provider) |
||
461 | * - If a combined file includes files that are provided by prior |
||
462 | * scripts, then these should be excluded from the combined file. |
||
463 | * - If a combined file includes files that are provided by later |
||
464 | * scripts, then these files should be included in the combined |
||
465 | * file, but we can't block the later script either (possible double |
||
466 | * up of file). |
||
467 | * |
||
468 | * @return array Array of provided files (map of $path => $path) |
||
469 | */ |
||
470 | public function getProvidedScripts() |
||
494 | |||
495 | /** |
||
496 | * Returns an array of required JavaScript, excluding blocked |
||
497 | * and duplicates of provided files. |
||
498 | * |
||
499 | * @return array |
||
500 | */ |
||
501 | public function getJavascript() |
||
509 | |||
510 | /** |
||
511 | * Gets all javascript, including blocked files. Unwraps the array into a non-associative list |
||
512 | * |
||
513 | * @return array Indexed array of javascript files |
||
514 | */ |
||
515 | protected function getAllJavascript() |
||
519 | |||
520 | /** |
||
521 | * Register the given JavaScript code into the list of requirements |
||
522 | * |
||
523 | * @param string $script The script content as a string (without enclosing <script> tag) |
||
524 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
525 | */ |
||
526 | public function customScript($script, $uniquenessID = null) |
||
534 | |||
535 | /** |
||
536 | * Return all registered custom scripts |
||
537 | * |
||
538 | * @return array |
||
539 | */ |
||
540 | public function getCustomScripts() |
||
544 | |||
545 | /** |
||
546 | * Register the given CSS styles into the list of requirements |
||
547 | * |
||
548 | * @param string $script CSS selectors as a string (without enclosing <style> tag) |
||
549 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
550 | */ |
||
551 | public function customCSS($script, $uniquenessID = null) |
||
559 | |||
560 | /** |
||
561 | * Return all registered custom CSS |
||
562 | * |
||
563 | * @return array |
||
564 | */ |
||
565 | public function getCustomCSS() |
||
569 | |||
570 | /** |
||
571 | * Add the following custom HTML code to the <head> section of the page |
||
572 | * |
||
573 | * @param string $html Custom HTML code |
||
574 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
575 | */ |
||
576 | public function insertHeadTags($html, $uniquenessID = null) |
||
584 | |||
585 | /** |
||
586 | * Return all custom head tags |
||
587 | * |
||
588 | * @return array |
||
589 | */ |
||
590 | public function getCustomHeadTags() |
||
594 | |||
595 | /** |
||
596 | * Include the content of the given JavaScript file in the list of requirements. Dollar-sign |
||
597 | * variables will be interpolated with values from $vars similar to a .ss template. |
||
598 | * |
||
599 | * @param string $file The template file to load, relative to docroot |
||
600 | * @param string[] $vars The array of variables to interpolate. |
||
601 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
602 | */ |
||
603 | public function javascriptTemplate($file, $vars, $uniquenessID = null) |
||
619 | |||
620 | /** |
||
621 | * Register the given stylesheet into the list of requirements. |
||
622 | * |
||
623 | * @param string $file The CSS file to load, relative to site root |
||
624 | * @param string $media Comma-separated list of media types to use in the link tag |
||
625 | * (e.g. 'screen,projector') |
||
626 | */ |
||
627 | public function css($file, $media = null) |
||
635 | |||
636 | /** |
||
637 | * Convert a file of the form "vendor/package:resource" into a BASE_PATH-relative file |
||
638 | * For other files, reutrn original value |
||
639 | * |
||
640 | * @param string $file |
||
641 | * @return string |
||
642 | */ |
||
643 | protected function parseModuleResourceReference($file) { |
||
655 | |||
656 | /** |
||
657 | * Remove a css requirement |
||
658 | * |
||
659 | * @param string $file |
||
660 | */ |
||
661 | protected function unsetCSS($file) |
||
665 | |||
666 | /** |
||
667 | * Get the list of registered CSS file requirements, excluding blocked files |
||
668 | * |
||
669 | * @return array Associative array of file to spec |
||
670 | */ |
||
671 | public function getCSS() |
||
675 | |||
676 | /** |
||
677 | * Gets all CSS files requirements, including blocked |
||
678 | * |
||
679 | * @return array Associative array of file to spec |
||
680 | */ |
||
681 | protected function getAllCSS() |
||
685 | |||
686 | /** |
||
687 | * Gets the list of all blocked files |
||
688 | * |
||
689 | * @return array |
||
690 | */ |
||
691 | public function getBlocked() |
||
695 | |||
696 | /** |
||
697 | * Clear either a single or all requirements |
||
698 | * |
||
699 | * Caution: Clearing single rules added via customCSS and customScript only works if you |
||
700 | * originally specified a $uniquenessID. |
||
701 | * |
||
702 | * @param string|int $fileOrID |
||
703 | */ |
||
704 | public function clear($fileOrID = null) |
||
727 | |||
728 | /** |
||
729 | * Restore requirements cleared by call to Requirements::clear |
||
730 | */ |
||
731 | public function restore() |
||
739 | |||
740 | /** |
||
741 | * Block inclusion of a specific file |
||
742 | * |
||
743 | * The difference between this and {@link clear} is that the calling order does not matter; |
||
744 | * {@link clear} must be called after the initial registration, whereas {@link block} can be |
||
745 | * used in advance. This is useful, for example, to block scripts included by a superclass |
||
746 | * without having to override entire functions and duplicate a lot of code. |
||
747 | * |
||
748 | * Note that blocking should be used sparingly because it's hard to trace where an file is |
||
749 | * being blocked from. |
||
750 | * |
||
751 | * @param string|int $fileOrID |
||
752 | */ |
||
753 | public function block($fileOrID) |
||
757 | |||
758 | /** |
||
759 | * Remove an item from the block list |
||
760 | * |
||
761 | * @param string|int $fileOrID |
||
762 | */ |
||
763 | public function unblock($fileOrID) |
||
767 | |||
768 | /** |
||
769 | * Removes all items from the block list |
||
770 | */ |
||
771 | public function unblockAll() |
||
775 | |||
776 | /** |
||
777 | * Update the given HTML content with the appropriate include tags for the registered |
||
778 | * requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, |
||
779 | * including a head and body tag. |
||
780 | * |
||
781 | * @param string $content HTML content that has already been parsed from the $templateFile |
||
782 | * through {@link SSViewer} |
||
783 | * @return string HTML content augmented with the requirements tags |
||
784 | */ |
||
785 | public function includeInHTML($content) |
||
871 | |||
872 | /** |
||
873 | * Given a block of HTML, insert the given scripts at the bottom before |
||
874 | * the closing </body> tag |
||
875 | * |
||
876 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
877 | * @param string $content HTML body |
||
878 | * @return string Merged HTML |
||
879 | */ |
||
880 | protected function insertScriptsAtBottom($jsRequirements, $content) |
||
891 | |||
892 | /** |
||
893 | * Given a block of HTML, insert the given scripts inside the <body></body> |
||
894 | * |
||
895 | * @param string $jsRequirements String containing one or more javascript <script /> tags |
||
896 | * @param string $content HTML body |
||
897 | * @return string Merged HTML |
||
898 | */ |
||
899 | protected function insertScriptsIntoBody($jsRequirements, $content) |
||
928 | |||
929 | /** |
||
930 | * Given a block of HTML, insert the given code inside the <head></head> block |
||
931 | * |
||
932 | * @param string $jsRequirements String containing one or more html tags |
||
933 | * @param string $content HTML body |
||
934 | * @return string Merged HTML |
||
935 | */ |
||
936 | protected function insertTagsIntoHead($jsRequirements, $content) |
||
945 | |||
946 | /** |
||
947 | * Safely escape a literal string for use in preg_replace replacement |
||
948 | * |
||
949 | * @param string $replacement |
||
950 | * @return string |
||
951 | */ |
||
952 | protected function escapeReplacement($replacement) |
||
956 | |||
957 | /** |
||
958 | * Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given |
||
959 | * HTTP Response |
||
960 | * |
||
961 | * @param HTTPResponse $response |
||
962 | */ |
||
963 | public function includeInResponse(HTTPResponse $response) |
||
992 | |||
993 | /** |
||
994 | * Add i18n files from the given javascript directory. SilverStripe expects that the given |
||
995 | * directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, |
||
996 | * etc. |
||
997 | * |
||
998 | * @param string $langDir The JavaScript lang directory, relative to the site root, e.g., |
||
999 | * 'framework/javascript/lang' |
||
1000 | * @param bool $return Return all relative file paths rather than including them in |
||
1001 | * requirements |
||
1002 | * |
||
1003 | * @return array|null All relative files if $return is true, or null otherwise |
||
1004 | */ |
||
1005 | public function add_i18n_javascript($langDir, $return = false) |
||
1037 | |||
1038 | /** |
||
1039 | * Finds the path for specified file |
||
1040 | * |
||
1041 | * @param string $fileOrUrl |
||
1042 | * @return string|bool |
||
1043 | */ |
||
1044 | protected function pathForFile($fileOrUrl) |
||
1053 | |||
1054 | /** |
||
1055 | * Concatenate several css or javascript files into a single dynamically generated file. This |
||
1056 | * increases performance by fewer HTTP requests. |
||
1057 | * |
||
1058 | * The combined file is regenerated based on every file modification time. Optionally a |
||
1059 | * rebuild can be triggered by appending ?flush=1 to the URL. |
||
1060 | * |
||
1061 | * All combined files will have a comment on the start of each concatenated file denoting their |
||
1062 | * original position. |
||
1063 | * |
||
1064 | * CAUTION: You're responsible for ensuring that the load order for combined files is |
||
1065 | * retained - otherwise combining JavaScript files can lead to functional errors in the |
||
1066 | * JavaScript logic, and combining CSS can lead to incorrect inheritance. You can also |
||
1067 | * only include each file once across all includes and combinations in a single page load. |
||
1068 | * |
||
1069 | * CAUTION: Combining CSS Files discards any "media" information. |
||
1070 | * |
||
1071 | * Example for combined JavaScript: |
||
1072 | * <code> |
||
1073 | * Requirements::combine_files( |
||
1074 | * 'foobar.js', |
||
1075 | * array( |
||
1076 | * 'mysite/javascript/foo.js', |
||
1077 | * 'mysite/javascript/bar.js', |
||
1078 | * ), |
||
1079 | * array( |
||
1080 | * 'async' => true, |
||
1081 | * 'defer' => true, |
||
1082 | * ) |
||
1083 | * ); |
||
1084 | * </code> |
||
1085 | * |
||
1086 | * Example for combined CSS: |
||
1087 | * <code> |
||
1088 | * Requirements::combine_files( |
||
1089 | * 'foobar.css', |
||
1090 | * array( |
||
1091 | * 'mysite/javascript/foo.css', |
||
1092 | * 'mysite/javascript/bar.css', |
||
1093 | * ), |
||
1094 | * array( |
||
1095 | * 'media' => 'print', |
||
1096 | * ) |
||
1097 | * ); |
||
1098 | * </code> |
||
1099 | * |
||
1100 | * @param string $combinedFileName Filename of the combined file relative to docroot |
||
1101 | * @param array $files Array of filenames relative to docroot |
||
1102 | * @param array $options Array of options for combining files. Available options are: |
||
1103 | * - 'media' : If including CSS Files, you can specify a media type |
||
1104 | * - 'async' : If including JavaScript Files, boolean value to set async attribute to script tag |
||
1105 | * - 'defer' : If including JavaScript Files, boolean value to set defer attribute to script tag |
||
1106 | */ |
||
1107 | public function combineFiles($combinedFileName, $files, $options = array()) |
||
1165 | |||
1166 | /** |
||
1167 | * Return path and type of given combined file |
||
1168 | * |
||
1169 | * @param string|array $file Either a file path, or an array spec |
||
1170 | * @return array array with two elements, path and type of file |
||
1171 | */ |
||
1172 | protected function parseCombinedFile($file) |
||
1196 | |||
1197 | /** |
||
1198 | * Return all combined files; keys are the combined file names, values are lists of |
||
1199 | * associative arrays with 'files', 'type', and 'media' keys for details about this |
||
1200 | * combined file. |
||
1201 | * |
||
1202 | * @return array |
||
1203 | */ |
||
1204 | public function getCombinedFiles() |
||
1208 | |||
1209 | /** |
||
1210 | * Includes all combined files, including blocked ones |
||
1211 | * |
||
1212 | * @return array |
||
1213 | */ |
||
1214 | protected function getAllCombinedFiles() |
||
1218 | |||
1219 | /** |
||
1220 | * Clears all combined files |
||
1221 | */ |
||
1222 | public function deleteAllCombinedFiles() |
||
1229 | |||
1230 | /** |
||
1231 | * Clear all registered CSS and JavaScript file combinations |
||
1232 | */ |
||
1233 | public function clearCombinedFiles() |
||
1237 | |||
1238 | /** |
||
1239 | * Do the heavy lifting involved in combining the combined files. |
||
1240 | */ |
||
1241 | public function processCombinedFiles() |
||
1307 | |||
1308 | /** |
||
1309 | * Given a set of files, combine them (as necessary) and return the url |
||
1310 | * |
||
1311 | * @param string $combinedFile Filename for this combined file |
||
1312 | * @param array $fileList List of files to combine |
||
1313 | * @param string $type Either 'js' or 'css' |
||
1314 | * @return string|null URL to this resource, if there are files to combine |
||
1315 | * @throws Exception |
||
1316 | */ |
||
1317 | protected function getCombinedFileURL($combinedFile, $fileList, $type) |
||
1384 | |||
1385 | /** |
||
1386 | * Given a filename and list of files, generate a new filename unique to these files |
||
1387 | * |
||
1388 | * @param string $combinedFile |
||
1389 | * @param array $fileList |
||
1390 | * @return string |
||
1391 | */ |
||
1392 | protected function hashedCombinedFilename($combinedFile, $fileList) |
||
1399 | |||
1400 | /** |
||
1401 | * Check if combined files are enabled |
||
1402 | * |
||
1403 | * @return bool |
||
1404 | */ |
||
1405 | public function getCombinedFilesEnabled() |
||
1419 | |||
1420 | /** |
||
1421 | * For a given filelist, determine some discriminating value to determine if |
||
1422 | * any of these files have changed. |
||
1423 | * |
||
1424 | * @param array $fileList List of files |
||
1425 | * @return string SHA1 bashed file hash |
||
1426 | */ |
||
1427 | protected function hashOfFiles($fileList) |
||
1441 | |||
1442 | /** |
||
1443 | * Registers the given themeable stylesheet as required. |
||
1444 | * |
||
1445 | * A CSS file in the current theme path name 'themename/css/$name.css' is first searched for, |
||
1446 | * and it that doesn't exist and the module parameter is set then a CSS file with that name in |
||
1447 | * the module is used. |
||
1448 | * |
||
1449 | * @param string $name The name of the file - eg '/css/File.css' would have the name 'File' |
||
1450 | * @param string $media Comma-separated list of media types to use in the link tag |
||
1451 | * (e.g. 'screen,projector') |
||
1452 | */ |
||
1453 | 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) |
||
1493 | |||
1494 | /** |
||
1495 | * Output debugging information. |
||
1496 | */ |
||
1497 | public function debug() |
||
1506 | } |
||
1507 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.