diff --git a/core/lib/Drupal/Core/Asset/AssetDumper.php b/core/lib/Drupal/Core/Asset/AssetDumper.php index 533f602..7c3afdd 100644 --- a/core/lib/Drupal/Core/Asset/AssetDumper.php +++ b/core/lib/Drupal/Core/Asset/AssetDumper.php @@ -7,7 +7,7 @@ /** * Dumps a CSS or JavaScript asset. */ -class AssetDumper implements AssetDumperInterface { +class AssetDumper implements AssetDumperUriInterface { /** * {@inheritdoc} @@ -16,15 +16,20 @@ class AssetDumper implements AssetDumperInterface { * the aggregated contents of the files in $data. This forces proxies and * browsers to download new CSS when the CSS changes. */ - public function dump($data, $file_extension, $uri = NULL) { - // Create the css/ or js/ path within the files folder. + public function dump($data, $file_extension) { + $path = 'public://' . $file_extension; + // Prefix filename to prevent blocking by firewalls which reject files + // starting with "ad*". + $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension; + $uri = $path . '/' . $filename; + return $this->dumpToUri($data, $file_extension, $uri); + } + + /** + * {@inheritdoc} + */ + public function dumpToUri($data, $file_extension, $uri) { $path = 'public://' . $file_extension; - if (!isset($uri)) { - // Prefix filename to prevent blocking by firewalls which reject files - // starting with "ad*". - $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension; - $uri = $path . '/' . $filename; - } // Create the CSS or JS file. file_prepare_directory($path, FILE_CREATE_DIRECTORY); if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) { diff --git a/core/lib/Drupal/Core/Asset/AssetDumperInterface.php b/core/lib/Drupal/Core/Asset/AssetDumperInterface.php index e7d0ac9..2b53eb1 100644 --- a/core/lib/Drupal/Core/Asset/AssetDumperInterface.php +++ b/core/lib/Drupal/Core/Asset/AssetDumperInterface.php @@ -15,12 +15,9 @@ * @param string $file_extension * The file extension of this asset. * - * @param string $uri - * (optional) The file URI to write to. - * * @return string * An URI to access the dumped asset. */ - public function dump($data, $file_extension, $uri = NULL); + public function dump($data, $file_extension); } diff --git a/core/modules/system/src/Controller/AssetControllerBase.php b/core/modules/system/src/Controller/AssetControllerBase.php index b2a32fa..03f44da 100644 --- a/core/modules/system/src/Controller/AssetControllerBase.php +++ b/core/modules/system/src/Controller/AssetControllerBase.php @@ -65,7 +65,7 @@ /** * An asset dumper. * - * @var \Drupal\Core\Asset\AssetDumperInterface + * @var \Drupal\Core\Asset\AssetDumperUriInterface */ protected $dumper; @@ -110,10 +110,10 @@ * The asset grouper. * @param \Drupal\Core\Asset\AssetOptimizerInterface * The optimizer for a single asset. - * @param \Drupal\Core\Asset\AssetDumperInterface + * @param \Drupal\Core\Asset\AssetDumperUriInterface * The asset dumper. */ - public function __construct($library_dependency_resolver, $asset_resolver, $theme_initialization, $theme_manager, $grouper, $optimizer, $dumper) { + public function __construct(LibraryDependencyResolverInterface $library_dependency_resolver, AssetResolverInterface $asset_resolver, ThemeInitializationInterface $theme_initialization, ThemeManagerInterface $theme_manager, AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperUriInterface $dumper) { $this->libraryDependencyResolver = $library_dependency_resolver; $this->assetResolver = $asset_resolver; $this->themeInitialization = $theme_initialization; @@ -162,9 +162,8 @@ public function deliver(Request $request, $file_name) { if ($request->query->has('already_loaded')) { $attached_assets->setAlreadyLoadedLibraries($request->query->get('already_loaded')); } - $key_and_group = $this->getKeyAndGroup($attached_assets, $group_delta, $request); - $key = $key_and_group['key']; - $group = $key_and_group['group']; + $group = $this->getGroup($attached_assets, $group_delta, $request); + $key = $this->generateHash($group); $hash = $file_parts[2]; // The hash from the library definitions in code may not match the hash from diff --git a/core/modules/system/src/Controller/CssAssetController.php b/core/modules/system/src/Controller/CssAssetController.php index 8f1b0b5..112dbfb 100644 --- a/core/modules/system/src/Controller/CssAssetController.php +++ b/core/modules/system/src/Controller/CssAssetController.php @@ -49,12 +49,7 @@ protected function getKeyAndGroup(AttachedAssetsInterface $attached_assets, $gro if (!isset($groups[$group_delta])) { throw new BadRequestHttpException('Invalid filename.'); } - $group = $groups[$group_delta]; - $key = $this->generateHash($groups); - return [ - 'group' => $group, - 'key' => $key, - ]; + return $groups[$group_delta]; } /** diff --git a/core/modules/system/src/Controller/JsAssetController.php b/core/modules/system/src/Controller/JsAssetController.php index 4fdf401..6a92a85 100644 --- a/core/modules/system/src/Controller/JsAssetController.php +++ b/core/modules/system/src/Controller/JsAssetController.php @@ -42,7 +42,7 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - protected function getKeyAndGroup(AttachedAssetsInterface $attached_assets, $group_delta, $request) { + protected function getGroup(AttachedAssetsInterface $attached_assets, $group_delta, $request) { // The header and footer scripts are two distinct sets of asset groups. The // $group_key is not sufficient to find the group, we also need to locate it // within either the header or footer set. @@ -61,11 +61,7 @@ protected function getKeyAndGroup(AttachedAssetsInterface $attached_assets, $gro throw new BadRequestHttpException('Invalid filename.'); } $group = $groups[$group_delta]; - $key = $this->generateHash($groups); - return [ - 'group' => $group, - 'key' => $key, - ]; + return $group; } /**