.../Core/Asset/AssetCollectionGrouperInterface.php | 3 +- .../Asset/AssetCollectionOptimizerInterface.php | 3 +- .../Asset/AssetCollectionRendererInterface.php | 3 +- core/lib/Drupal/Core/Asset/AssetDumper.php | 2 +- .../lib/Drupal/Core/Asset/AssetDumperInterface.php | 3 +- .../Drupal/Core/Asset/AssetOptimizerInterface.php | 3 +- .../lib/Drupal/Core/Asset/CssCollectionGrouper.php | 8 +++-- .../Drupal/Core/Asset/CssCollectionOptimizer.php | 24 +++++++++----- .../Drupal/Core/Asset/CssCollectionRenderer.php | 33 +++++++++++--------- core/lib/Drupal/Core/Asset/CssOptimizer.php | 9 ++---- core/lib/Drupal/Core/Asset/JsCollectionGrouper.php | 10 +++--- .../Drupal/Core/Asset/JsCollectionOptimizer.php | 21 ++++++++----- .../lib/Drupal/Core/Asset/JsCollectionRenderer.php | 2 +- .../Tests/Common/CascadingStylesheetsTest.php | 2 +- .../Drupal/system/Tests/Common/JavaScriptTest.php | 7 ++++- 15 files changed, 79 insertions(+), 54 deletions(-) diff --git a/core/lib/Drupal/Core/Asset/AssetCollectionGrouperInterface.php b/core/lib/Drupal/Core/Asset/AssetCollectionGrouperInterface.php index 00d427f..94f9e85 100644 --- a/core/lib/Drupal/Core/Asset/AssetCollectionGrouperInterface.php +++ b/core/lib/Drupal/Core/Asset/AssetCollectionGrouperInterface.php @@ -1,7 +1,7 @@ optimizer->optimize($css_asset); } - // Per the W3C specification at http://www.w3.org/TR/REC-CSS2/cascade.html#at-import, - // @import rules must proceed any other style, so we move those to the top. + // Per the W3C specification at + // http://www.w3.org/TR/REC-CSS2/cascade.html#at-import, @import + // rules must proceed any other style, so we move those to the + // top. $regexp = '/@import[^;]+;/i'; preg_match_all($regexp, $data, $matches); $data = preg_replace($regexp, '', $data); @@ -150,12 +152,18 @@ public function optimize(array $css_assets) { /** * Generate a hash for a given group of CSS assets. + * + * @param array $css_group + * A group of CSS assets. + * + * @return string + * A hash to uniquely identify the given group of CSS assets. */ protected function generateHash(array $css_group) { $css_data = array(); foreach ($css_group['items'] as $css_file) { $css_data[] = $css_file['data']; } - return hash('sha256', serialize($css_data)); + return hash('sha256', serialize($css_data)); } } diff --git a/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php b/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php index 527dd5c..6d36ede 100644 --- a/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php @@ -7,9 +7,10 @@ namespace Drupal\Core\Asset; use Drupal\Core\Asset\AssetCollectionRendererInterface; +use Drupal\Component\Utility\String; /** - * + * Renders CSS assets. */ class CssCollectionRenderer implements AssetCollectionRendererInterface { @@ -44,7 +45,8 @@ public function render(array $css_assets) { return array($css_asset['type'], $css_asset['preprocess'], $css_asset['group'], $css_asset['every_page'], $css_asset['media'], $css_asset['browsers']); }; - // Loop through all CSS assets, by key, to allow for the special IE workaround. + // Loop through all CSS assets, by key, to allow for the special IE + // workaround. $css_assets_keys = array_keys($css_assets); for ($i = 0; $i < count($css_assets_keys); $i++) { $css_asset = $css_assets[$css_assets_keys[$i]]; @@ -101,11 +103,11 @@ public function render(array $css_assets) { $next_css_asset = $css_asset; $current_ie_group_key = $get_ie_group_key($css_asset); do { - // The dummy query string needs to be added to the URL to control - // browser-caching. IE7 does not support a media type on the - // @import statement, so we instead specify the media for the - // group on the STYLE tag. - $import[] = '@import url("' . check_plain(file_create_url($next_css_asset['data']) . '?' . $query_string) . '");'; + // The dummy query string needs to be added to the URL to + // control browser-caching. IE7 does not support a media type on + // the @import statement, so we instead specify the media for + // the group on the STYLE tag. + $import[] = '@import url("' . String::checkPlain(file_create_url($next_css_asset['data']) . '?' . $query_string) . '");'; // Move the outer for loop skip the next item, since we // processed it here. $i = $j; @@ -119,16 +121,17 @@ public function render(array $css_assets) { } } while ($get_ie_group_key($next_css_asset) == $current_ie_group_key); - // In addition to IE's limit of 31 total CSS inclusion tags, it also - // has a limit of 31 @import statements per STYLE tag. + // In addition to IE's limit of 31 total CSS inclusion tags, it + // also has a limit of 31 @import statements per STYLE tag. while (!empty($import)) { $import_batch = array_slice($import, 0, 31); $import = array_slice($import, 31); $element = $style_element_defaults; // This simplifies the JavaScript regex, allowing each line - // (separated by \n) to be treated as a completely different string. - // This means that we can use ^ and $ on one line at a time, and not - // worry about style tags since they'll never match the regex. + // (separated by \n) to be treated as a completely different + // string. This means that we can use ^ and $ on one line at a + // time, and not worry about style tags since they'll never + // match the regex. $element['#value'] = "\n" . implode("\n", $import_batch) . "\n"; $element['#attributes']['media'] = $css_asset['media']; $element['#browsers'] = $css_asset['browsers']; @@ -145,9 +148,9 @@ public function render(array $css_assets) { $element['#value'] = $css_asset['data']; $element['#attributes']['media'] = $css_asset['media']; $element['#browsers'] = $css_asset['browsers']; - // For inline CSS to validate as XHTML, all CSS containing XHTML needs to be - // wrapped in CDATA. To make that backwards compatible with HTML 4, we need to - // comment out the CDATA-tag. + // For inline CSS to validate as XHTML, all CSS containing XHTML needs + // to be wrapped in CDATA. To make that backwards compatible with HTML + // 4, we need to comment out the CDATA-tag. $element['#value_prefix'] = "\n/* */\n"; $elements[] = $element; diff --git a/core/lib/Drupal/Core/Asset/CssOptimizer.php b/core/lib/Drupal/Core/Asset/CssOptimizer.php index c047ce1..8865623 100644 --- a/core/lib/Drupal/Core/Asset/CssOptimizer.php +++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php @@ -9,14 +9,13 @@ use Drupal\Core\Asset\AssetOptimizerInterface; /** - * + * Optimizes a CSS asset. */ class CssOptimizer implements AssetOptimizerInterface { /** * {@inheritdoc} */ - // @see drupal_aggregate_css() public function optimize(array $css_asset) { if (!in_array($css_asset['type'], array('file', 'inline'))) { throw new \Exception('Only file or inline CSS assets can be optimized.'); @@ -36,7 +35,6 @@ public function optimize(array $css_asset) { /** * Build aggregate CSS file. */ - // @see drupal_build_css_cache() protected function processFile($css_asset) { $contents = $this->loadFile($css_asset['data'], TRUE); @@ -73,7 +71,6 @@ protected function processFile($css_asset) { * @return * Contents of the stylesheet, including any resolved @import commands. */ - // @see drupal_load_stylesheet() public function loadFile($file, $optimize = NULL, $reset_basepath = TRUE) { // These statics are not cache variables, so we don't use drupal_static(). static $_optimize, $basepath; @@ -110,9 +107,8 @@ public function loadFile($file, $optimize = NULL, $reset_basepath = TRUE) { * This function is used for recursive loading of stylesheets and * returns the stylesheet content with all url() paths corrected. * - * @see loadFile() + * @see Drupal\Core\Asset\AssetOptimizerInterface::loadFile() */ - // @see _drupal_load_stylesheet() protected function loadNestedFile($matches) { $filename = $matches[1]; // Load the imported stylesheet and replace @import commands in there as @@ -143,7 +139,6 @@ protected function loadNestedFile($matches) { * @return * Contents of the stylesheet including the imported stylesheets. */ - // @see drupal_load_stylesheet_content() protected function processCss($contents, $optimize = FALSE) { // Remove multiple charset declarations for standards compliance (and fixing Safari problems). $contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents); diff --git a/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php b/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php index fb039b8..9f0aed0 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionGrouper.php @@ -9,7 +9,7 @@ use Drupal\Core\Asset\AssetCollectionGrouperInterface; /** - * + * Groups JavaScript assets. */ class JsCollectionGrouper implements AssetCollectionGrouperInterface { @@ -34,10 +34,10 @@ public function group(array $js_assets) { $current_group_keys = NULL; $index = -1; foreach ($js_assets as $item) { - // The browsers for which the JavaScript item needs to be loaded is part of - // the information that determines when a new group is needed, but the order - // of keys in the array doesn't matter, and we don't want a new group if all - // that's different is that order. + // The browsers for which the JavaScript item needs to be loaded is part + // of the information that determines when a new group is needed, but the + // order of keys in the array doesn't matter, and we don't want a new + // group if all that's different is that order. ksort($item['browsers']); switch ($item['type']) { diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php index 5b1b0e5..9c6f7e2 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php @@ -6,25 +6,25 @@ namespace Drupal\Core\Asset; -use Drupal; +use \Drupal; use Drupal\Core\Asset\AssetCollectionOptimizerInterface; /** - * + * Optimizes JavaScript assets. */ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface { /** * A JS asset grouper. * - * @var \Drupal\Core\Asset\JsCollectionGrouper object. + * @var \Drupal\Core\Asset\JsCollectionGrouper */ protected $grouper; /** * An asset dumper. * - * @var \Drupal\Core\Asset\AssetDumper object. + * @var \Drupal\Core\Asset\AssetDumper */ protected $dumper; @@ -93,7 +93,8 @@ public function optimize(array $js_assets) { $data = ''; foreach ($js_group['items'] as $js_asset) { $data .= file_get_contents($js_asset['data']); - // Append a ';' and a newline after each JS file to prevent them from running together. + // Append a ';' and a newline after each JS file to prevent them + // from running together. $data .= ";\n"; } // Dump the optimized JS for this group into an aggregate file. @@ -127,13 +128,19 @@ public function optimize(array $js_assets) { } /** - * Generate a hash for a given group of JS assets. + * Generate a hash for a given group of JavaScript assets. + * + * @param array $js_group + * A group of JavaScript assets. + * + * @return string + * A hash to uniquely identify the given group of JavaScript assets. */ protected function generateHash(array $js_group) { $js_data = array(); foreach ($js_group['items'] as $js_file) { $js_data[] = $js_file['data']; } - return hash('sha256', serialize($js_data)); + return hash('sha256', serialize($js_data)); } } diff --git a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php index 6f9323e..b9f6582 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php @@ -9,7 +9,7 @@ use Drupal\Core\Asset\AssetCollectionRendererInterface; /** - * + * Renders JavaScript assets. */ class JsCollectionRenderer implements AssetCollectionRendererInterface { diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php index 602d34a..0411d11 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php @@ -100,7 +100,7 @@ function testRenderExternal() { */ function testRenderInlinePreprocess() { // Turn on CSS aggregation to allow for preprocessing. - $config = config('system.performance'); + $config = $this->container->get('config.factory')->get('system.performance'); $config->set('css.preprocess', 1); $css = 'body { padding: 0px; }'; diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php index a00f2b5..c8d0570 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -573,7 +573,12 @@ function testAddJsFileWithQueryString() { } /** - * Calculates the aggregated file name of a group of JavaScript assets. + * Calculates the aggregated file URI of a group of JavaScript assets. + * + * @param array $js_assets + * A group of JavaScript assets. + * @return string + * A file URI. * * @see testAggregation() * @see testAggregationOrder()