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 |
||
| 462 | class Requirements_Backend |
||
| 463 | { |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Whether to add caching query params to the requests for file-based requirements. |
||
| 467 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
| 468 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
| 469 | * while automatically busting this cache every time the file is changed. |
||
| 470 | * |
||
| 471 | * @var bool |
||
| 472 | */ |
||
| 473 | protected $suffixRequirements = true; |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Whether to combine CSS and JavaScript files |
||
| 477 | * |
||
| 478 | * @var bool |
||
| 479 | */ |
||
| 480 | protected $combinedFilesEnabled = true; |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Determine if files should be combined automatically on dev mode. |
||
| 484 | * |
||
| 485 | * By default combined files will not be combined except in test or |
||
| 486 | * live environments. Turning this on will allow for pre-combining of files in development mode. |
||
| 487 | * |
||
| 488 | * @config |
||
| 489 | * @var bool |
||
| 490 | */ |
||
| 491 | private static $combine_in_dev = false; |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Paths to all required JavaScript files relative to docroot |
||
| 495 | * |
||
| 496 | * @var array |
||
| 497 | */ |
||
| 498 | protected $javascript = array(); |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Paths to all required CSS files relative to the docroot. |
||
| 502 | * |
||
| 503 | * @var array |
||
| 504 | */ |
||
| 505 | protected $css = array(); |
||
| 506 | |||
| 507 | /** |
||
| 508 | * All custom javascript code that is inserted into the page's HTML |
||
| 509 | * |
||
| 510 | * @var array |
||
| 511 | */ |
||
| 512 | protected $customScript = array(); |
||
| 513 | |||
| 514 | /** |
||
| 515 | * All custom CSS rules which are inserted directly at the bottom of the HTML <head> tag |
||
| 516 | * |
||
| 517 | * @var array |
||
| 518 | */ |
||
| 519 | protected $customCSS = array(); |
||
| 520 | |||
| 521 | /** |
||
| 522 | * All custom HTML markup which is added before the closing <head> tag, e.g. additional |
||
| 523 | * metatags. |
||
| 524 | * |
||
| 525 | * @var array |
||
| 526 | */ |
||
| 527 | protected $customHeadTags = array(); |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Remembers the file paths or uniquenessIDs of all Requirements cleared through |
||
| 531 | * {@link clear()}, so that they can be restored later. |
||
| 532 | * |
||
| 533 | * @var array |
||
| 534 | */ |
||
| 535 | protected $disabled = array(); |
||
| 536 | |||
| 537 | /** |
||
| 538 | * The file paths (relative to docroot) or uniquenessIDs of any included requirements which |
||
| 539 | * should be blocked when executing {@link inlcudeInHTML()}. This is useful, for example, |
||
| 540 | * to block scripts included by a superclass without having to override entire functions and |
||
| 541 | * duplicate a lot of code. |
||
| 542 | * |
||
| 543 | * Use {@link unblock()} or {@link unblock_all()} to revert changes. |
||
| 544 | * |
||
| 545 | * @var array |
||
| 546 | */ |
||
| 547 | protected $blocked = array(); |
||
| 548 | |||
| 549 | /** |
||
| 550 | * A list of combined files registered via {@link combine_files()}. Keys are the output file |
||
| 551 | * names, values are lists of input files. |
||
| 552 | * |
||
| 553 | * @var array |
||
| 554 | */ |
||
| 555 | protected $combinedFiles = array(); |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Use the JSMin library to minify any javascript file passed to {@link combine_files()}. |
||
| 559 | * |
||
| 560 | * @var bool |
||
| 561 | */ |
||
| 562 | protected $minifyCombinedJSFiles = true; |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Whether or not file headers should be written when combining files |
||
| 566 | * |
||
| 567 | * @var boolean |
||
| 568 | */ |
||
| 569 | protected $writeHeaderComment = true; |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Where to save combined files. By default they're placed in assets/_combinedfiles, however |
||
| 573 | * this may be an issue depending on your setup, especially for CSS files which often contain |
||
| 574 | * relative paths. |
||
| 575 | * |
||
| 576 | * @var string |
||
| 577 | */ |
||
| 578 | protected $combinedFilesFolder = null; |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Put all JavaScript includes at the bottom of the template before the closing <body> tag, |
||
| 582 | * rather than the default behaviour of placing them at the end of the <head> tag. This means |
||
| 583 | * script downloads won't block other HTTP requests, which can be a performance improvement. |
||
| 584 | * |
||
| 585 | * @var bool |
||
| 586 | */ |
||
| 587 | public $writeJavascriptToBody = true; |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Force the JavaScript to the bottom of the page, even if there's a script tag in the body already |
||
| 591 | * |
||
| 592 | * @var boolean |
||
| 593 | */ |
||
| 594 | protected $forceJSToBottom = false; |
||
| 595 | |||
| 596 | /** |
||
| 597 | * Configures the default prefix for combined files. |
||
| 598 | * |
||
| 599 | * This defaults to `_combinedfiles`, and is the folder within the configured asset backend that |
||
| 600 | * combined files will be stored in. If using a backend shared with other systems, it is usually |
||
| 601 | * necessary to distinguish combined files from other assets. |
||
| 602 | * |
||
| 603 | * @config |
||
| 604 | * @var string |
||
| 605 | */ |
||
| 606 | private static $default_combined_files_folder = '_combinedfiles'; |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Flag to include the hash in the querystring instead of the filename for combined files. |
||
| 610 | * |
||
| 611 | * By default the `<hash>` of the source files is appended to the end of the combined file |
||
| 612 | * (prior to the file extension). If combined files are versioned in source control or running |
||
| 613 | * in a distributed environment (such as one where the newest version of a file may not always be |
||
| 614 | * immediately available) then it may sometimes be necessary to disable this. When this is set to true, |
||
| 615 | * the hash will instead be appended via a querystring parameter to enable cache busting, but not in |
||
| 616 | * the filename itself. I.e. `assets/_combinedfiles/name.js?m=<hash>` |
||
| 617 | * |
||
| 618 | * @config |
||
| 619 | * @var bool |
||
| 620 | */ |
||
| 621 | private static $combine_hash_querystring = false; |
||
| 622 | |||
| 623 | /** |
||
| 624 | * @var GeneratedAssetHandler |
||
| 625 | */ |
||
| 626 | protected $assetHandler = null; |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Gets the backend storage for generated files |
||
| 630 | * |
||
| 631 | * @return GeneratedAssetHandler |
||
| 632 | */ |
||
| 633 | public function getAssetHandler() { |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Set a new asset handler for this backend |
||
| 639 | * |
||
| 640 | * @param GeneratedAssetHandler $handler |
||
| 641 | */ |
||
| 642 | public function setAssetHandler(GeneratedAssetHandler $handler) { |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Enable or disable the combination of CSS and JavaScript files |
||
| 648 | * |
||
| 649 | * @param bool $enable |
||
| 650 | */ |
||
| 651 | public function setCombinedFilesEnabled($enable) { |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Check if header comments are written |
||
| 657 | * |
||
| 658 | * @return bool |
||
| 659 | */ |
||
| 660 | public function getWriteHeaderComment() { |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Flag whether header comments should be written for each combined file |
||
| 666 | * |
||
| 667 | * @param bool $write |
||
| 668 | * @return $this |
||
| 669 | */ |
||
| 670 | public function setWriteHeaderComment($write) { |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Set the folder to save combined files in. By default they're placed in _combinedfiles, |
||
| 677 | * however this may be an issue depending on your setup, especially for CSS files which often |
||
| 678 | * contain relative paths. |
||
| 679 | * |
||
| 680 | * This must not include any 'assets' prefix |
||
| 681 | * |
||
| 682 | * @param string $folder |
||
| 683 | */ |
||
| 684 | public function setCombinedFilesFolder($folder) { |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Retrieve the combined files folder prefix |
||
| 690 | * |
||
| 691 | * @return string |
||
| 692 | */ |
||
| 693 | public function getCombinedFilesFolder() { |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Set whether to add caching query params to the requests for file-based requirements. |
||
| 702 | * Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by |
||
| 703 | * filemtime. This has the benefit of allowing the browser to cache the URL infinitely, |
||
| 704 | * while automatically busting this cache every time the file is changed. |
||
| 705 | * |
||
| 706 | * @param bool |
||
| 707 | */ |
||
| 708 | public function setSuffixRequirements($var) { |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Check whether we want to suffix requirements |
||
| 714 | * |
||
| 715 | * @return bool |
||
| 716 | */ |
||
| 717 | public function getSuffixRequirements() { |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Set whether you want to write the JS to the body of the page rather than at the end of the |
||
| 723 | * head tag. |
||
| 724 | * |
||
| 725 | * @param bool |
||
| 726 | * @return $this |
||
| 727 | */ |
||
| 728 | public function setWriteJavascriptToBody($var) { |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Check whether you want to write the JS to the body of the page rather than at the end of the |
||
| 735 | * head tag. |
||
| 736 | * |
||
| 737 | * @return bool |
||
| 738 | */ |
||
| 739 | public function getWriteJavascriptToBody() { |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Forces the JavaScript requirements to the end of the body, right before the closing tag |
||
| 745 | * |
||
| 746 | * @param bool |
||
| 747 | * @return $this |
||
| 748 | */ |
||
| 749 | public function setForceJSToBottom($var) { |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Check if the JavaScript requirements are written to the end of the body, right before the closing tag |
||
| 756 | * |
||
| 757 | * @return bool |
||
| 758 | */ |
||
| 759 | public function getForceJSToBottom() { |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Check if minify js files should be combined |
||
| 765 | * |
||
| 766 | * @return bool |
||
| 767 | */ |
||
| 768 | public function getMinifyCombinedJSFiles() { |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Set if combined js files should be minified |
||
| 774 | * |
||
| 775 | * @param bool $minify |
||
| 776 | * @return $this |
||
| 777 | */ |
||
| 778 | public function setMinifyCombinedJSFiles($minify) { |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Register the given JavaScript file as required. |
||
| 785 | * |
||
| 786 | * @param string $file Relative to docroot |
||
| 787 | */ |
||
| 788 | public function javascript($file) { |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Remove a javascript requirement |
||
| 794 | * |
||
| 795 | * @param string $file |
||
| 796 | */ |
||
| 797 | protected function unsetJavascript($file) { |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Returns an array of required JavaScript, excluding blocked |
||
| 803 | * |
||
| 804 | * @return array |
||
| 805 | */ |
||
| 806 | public function getJavascript() { |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Gets all javascript, including blocked files. Unwraps the array into a non-associative list |
||
| 812 | * |
||
| 813 | * @return array Indexed array of javascript files |
||
| 814 | */ |
||
| 815 | protected function getAllJavascript() { |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Register the given JavaScript code into the list of requirements |
||
| 821 | * |
||
| 822 | * @param string $script The script content as a string (without enclosing <script> tag) |
||
| 823 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
| 824 | */ |
||
| 825 | public function customScript($script, $uniquenessID = null) { |
||
| 834 | |||
| 835 | /** |
||
| 836 | * Return all registered custom scripts |
||
| 837 | * |
||
| 838 | * @return array |
||
| 839 | */ |
||
| 840 | public function getCustomScripts() { |
||
| 843 | |||
| 844 | /** |
||
| 845 | * Register the given CSS styles into the list of requirements |
||
| 846 | * |
||
| 847 | * @param string $script CSS selectors as a string (without enclosing <style> tag) |
||
| 848 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
| 849 | */ |
||
| 850 | public function customCSS($script, $uniquenessID = null) { |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Return all registered custom CSS |
||
| 860 | * |
||
| 861 | * @return array |
||
| 862 | */ |
||
| 863 | public function getCustomCSS() { |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Add the following custom HTML code to the <head> section of the page |
||
| 869 | * |
||
| 870 | * @param string $html Custom HTML code |
||
| 871 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
| 872 | */ |
||
| 873 | public function insertHeadTags($html, $uniquenessID = null) { |
||
| 880 | |||
| 881 | /** |
||
| 882 | * Return all custom head tags |
||
| 883 | * |
||
| 884 | * @return array |
||
| 885 | */ |
||
| 886 | public function getCustomHeadTags() { |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Include the content of the given JavaScript file in the list of requirements. Dollar-sign |
||
| 892 | * variables will be interpolated with values from $vars similar to a .ss template. |
||
| 893 | * |
||
| 894 | * @param string $file The template file to load, relative to docroot |
||
| 895 | * @param string[] $vars The array of variables to interpolate. |
||
| 896 | * @param string $uniquenessID A unique ID that ensures a piece of code is only added once |
||
| 897 | */ |
||
| 898 | public function javascriptTemplate($file, $vars, $uniquenessID = null) { |
||
| 911 | |||
| 912 | /** |
||
| 913 | * Register the given stylesheet into the list of requirements. |
||
| 914 | * |
||
| 915 | * @param string $file The CSS file to load, relative to site root |
||
| 916 | * @param string $media Comma-separated list of media types to use in the link tag |
||
| 917 | * (e.g. 'screen,projector') |
||
| 918 | */ |
||
| 919 | public function css($file, $media = null) { |
||
| 924 | |||
| 925 | /** |
||
| 926 | * Remove a css requirement |
||
| 927 | * |
||
| 928 | * @param string $file |
||
| 929 | */ |
||
| 930 | protected function unsetCSS($file) { |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Get the list of registered CSS file requirements, excluding blocked files |
||
| 936 | * |
||
| 937 | * @return array Associative array of file to spec |
||
| 938 | */ |
||
| 939 | public function getCSS() { |
||
| 942 | |||
| 943 | /** |
||
| 944 | * Gets all CSS files requirements, including blocked |
||
| 945 | * |
||
| 946 | * @return array Associative array of file to spec |
||
| 947 | */ |
||
| 948 | protected function getAllCSS() { |
||
| 951 | |||
| 952 | /** |
||
| 953 | * Gets the list of all blocked files |
||
| 954 | * |
||
| 955 | * @return array |
||
| 956 | */ |
||
| 957 | public function getBlocked() { |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Clear either a single or all requirements |
||
| 963 | * |
||
| 964 | * Caution: Clearing single rules added via customCSS and customScript only works if you |
||
| 965 | * originally specified a $uniquenessID. |
||
| 966 | * |
||
| 967 | * @param string|int $fileOrID |
||
| 968 | */ |
||
| 969 | public function clear($fileOrID = null) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Restore requirements cleared by call to Requirements::clear |
||
| 994 | */ |
||
| 995 | public function restore() { |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Block inclusion of a specific file |
||
| 1005 | * |
||
| 1006 | * The difference between this and {@link clear} is that the calling order does not matter; |
||
| 1007 | * {@link clear} must be called after the initial registration, whereas {@link block} can be |
||
| 1008 | * used in advance. This is useful, for example, to block scripts included by a superclass |
||
| 1009 | * without having to override entire functions and duplicate a lot of code. |
||
| 1010 | * |
||
| 1011 | * Note that blocking should be used sparingly because it's hard to trace where an file is |
||
| 1012 | * being blocked from. |
||
| 1013 | * |
||
| 1014 | * @param string|int $fileOrID |
||
| 1015 | */ |
||
| 1016 | public function block($fileOrID) { |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Remove an item from the block list |
||
| 1022 | * |
||
| 1023 | * @param string|int $fileOrID |
||
| 1024 | */ |
||
| 1025 | public function unblock($fileOrID) { |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Removes all items from the block list |
||
| 1031 | */ |
||
| 1032 | public function unblockAll() { |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Update the given HTML content with the appropriate include tags for the registered |
||
| 1038 | * requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, |
||
| 1039 | * including a head and body tag. |
||
| 1040 | * |
||
| 1041 | * @param string $templateFile No longer used, only retained for compatibility |
||
| 1042 | * @param string $content HTML content that has already been parsed from the $templateFile |
||
| 1043 | * through {@link SSViewer} |
||
| 1044 | * @return string HTML content augmented with the requirements tags |
||
| 1045 | */ |
||
| 1046 | public function includeInHTML($templateFile, $content) { |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given |
||
| 1136 | * HTTP Response |
||
| 1137 | * |
||
| 1138 | * @param SS_HTTPResponse $response |
||
| 1139 | */ |
||
| 1140 | public function includeInResponse(SS_HTTPResponse $response) { |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Add i18n files from the given javascript directory. SilverStripe expects that the given |
||
| 1167 | * directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, |
||
| 1168 | * etc. |
||
| 1169 | * |
||
| 1170 | * @param string $langDir The JavaScript lang directory, relative to the site root, e.g., |
||
| 1171 | * 'framework/javascript/lang' |
||
| 1172 | * @param bool $return Return all relative file paths rather than including them in |
||
| 1173 | * requirements |
||
| 1174 | * @param bool $langOnly Only include language files, not the base libraries |
||
| 1175 | * |
||
| 1176 | * @return array |
||
| 1177 | */ |
||
| 1178 | public function add_i18n_javascript($langDir, $return = false, $langOnly = false) { |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Finds the path for specified file |
||
| 1220 | * |
||
| 1221 | * @param string $fileOrUrl |
||
| 1222 | * @return string|bool |
||
| 1223 | */ |
||
| 1224 | protected function pathForFile($fileOrUrl) { |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Concatenate several css or javascript files into a single dynamically generated file. This |
||
| 1254 | * increases performance by fewer HTTP requests. |
||
| 1255 | * |
||
| 1256 | * The combined file is regenerated based on every file modification time. Optionally a |
||
| 1257 | * rebuild can be triggered by appending ?flush=1 to the URL. |
||
| 1258 | * |
||
| 1259 | * All combined files will have a comment on the start of each concatenated file denoting their |
||
| 1260 | * original position. |
||
| 1261 | * |
||
| 1262 | * CAUTION: You're responsible for ensuring that the load order for combined files is |
||
| 1263 | * retained - otherwise combining JavaScript files can lead to functional errors in the |
||
| 1264 | * JavaScript logic, and combining CSS can lead to incorrect inheritance. You can also |
||
| 1265 | * only include each file once across all includes and combinations in a single page load. |
||
| 1266 | * |
||
| 1267 | * CAUTION: Combining CSS Files discards any "media" information. |
||
| 1268 | * |
||
| 1269 | * Example for combined JavaScript: |
||
| 1270 | * <code> |
||
| 1271 | * Requirements::combine_files( |
||
| 1272 | * 'foobar.js', |
||
| 1273 | * array( |
||
| 1274 | * 'mysite/javascript/foo.js', |
||
| 1275 | * 'mysite/javascript/bar.js', |
||
| 1276 | * ) |
||
| 1277 | * ); |
||
| 1278 | * </code> |
||
| 1279 | * |
||
| 1280 | * Example for combined CSS: |
||
| 1281 | * <code> |
||
| 1282 | * Requirements::combine_files( |
||
| 1283 | * 'foobar.css', |
||
| 1284 | * array( |
||
| 1285 | * 'mysite/javascript/foo.css', |
||
| 1286 | * 'mysite/javascript/bar.css', |
||
| 1287 | * ) |
||
| 1288 | * ); |
||
| 1289 | * </code> |
||
| 1290 | * |
||
| 1291 | * @param string $combinedFileName Filename of the combined file relative to docroot |
||
| 1292 | * @param array $files Array of filenames relative to docroot |
||
| 1293 | * @param string $media If including CSS Files, you can specify a media type |
||
| 1294 | */ |
||
| 1295 | public function combineFiles($combinedFileName, $files, $media = null) { |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Return path and type of given combined file |
||
| 1351 | * |
||
| 1352 | * @param string|array $file Either a file path, or an array spec |
||
| 1353 | * @return array array with two elements, path and type of file |
||
| 1354 | */ |
||
| 1355 | protected function parseCombinedFile($file) { |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Return all combined files; keys are the combined file names, values are lists of |
||
| 1381 | * associative arrays with 'files', 'type', and 'media' keys for details about this |
||
| 1382 | * combined file. |
||
| 1383 | * |
||
| 1384 | * @return array |
||
| 1385 | */ |
||
| 1386 | public function getCombinedFiles() { |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Includes all combined files, including blocked ones |
||
| 1392 | * |
||
| 1393 | * @return type |
||
| 1394 | */ |
||
| 1395 | protected function getAllCombinedFiles() { |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Clears all combined files |
||
| 1401 | */ |
||
| 1402 | public function deleteAllCombinedFiles() { |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Clear all registered CSS and JavaScript file combinations |
||
| 1411 | */ |
||
| 1412 | public function clearCombinedFiles() { |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Do the heavy lifting involved in combining the combined files. |
||
| 1418 | */ |
||
| 1419 | public function processCombinedFiles() { |
||
| 1475 | |||
| 1476 | /** |
||
| 1477 | * Given a set of files, combine them (as necessary) and return the url |
||
| 1478 | * |
||
| 1479 | * @param string $combinedFile Filename for this combined file |
||
| 1480 | * @param array $fileList List of files to combine |
||
| 1481 | * @param string $type Either 'js' or 'css' |
||
| 1482 | * @return string URL to this resource |
||
| 1483 | */ |
||
| 1484 | protected function getCombinedFileURL($combinedFile, $fileList, $type) { |
||
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Given a filename and list of files, generate a new filename unique to these files |
||
| 1536 | * |
||
| 1537 | * @param string $name |
||
| 1538 | * @param array $files |
||
| 1539 | * @return string |
||
| 1540 | */ |
||
| 1541 | protected function hashedCombinedFilename($combinedFile, $fileList) { |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Check if combined files are enabled |
||
| 1550 | * |
||
| 1551 | * @return bool |
||
| 1552 | */ |
||
| 1553 | public function getCombinedFilesEnabled() { |
||
| 1576 | |||
| 1577 | /** |
||
| 1578 | * For a given filelist, determine some discriminating value to determine if |
||
| 1579 | * any of these files have changed. |
||
| 1580 | * |
||
| 1581 | * @param array $fileList List of files |
||
| 1582 | * @return string SHA1 bashed file hash |
||
| 1583 | */ |
||
| 1584 | protected function hashOfFiles($fileList) { |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Registers the given themeable stylesheet as required. |
||
| 1600 | * |
||
| 1601 | * A CSS file in the current theme path name 'themename/css/$name.css' is first searched for, |
||
| 1602 | * and it that doesn't exist and the module parameter is set then a CSS file with that name in |
||
| 1603 | * the module is used. |
||
| 1604 | * |
||
| 1605 | * @param string $name The name of the file - eg '/css/File.css' would have the name 'File' |
||
| 1606 | * @param string $module The module to fall back to if the css file does not exist in the |
||
| 1607 | * current theme. |
||
| 1608 | * @param string $media Comma-separated list of media types to use in the link tag |
||
| 1609 | * (e.g. 'screen,projector') |
||
| 1610 | */ |
||
| 1611 | public function themedCSS($name, $module = null, $media = null) { |
||
| 1629 | |||
| 1630 | /** |
||
| 1631 | * Output debugging information. |
||
| 1632 | */ |
||
| 1633 | public function debug() { |
||
| 1641 | |||
| 1642 | } |
||
| 1643 | |||
| 1658 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: