cdn_ui/src/Form/CdnSettingsForm.php | 4 ++-- src/CdnSettings.php | 3 ++- src/File/FileUrlGenerator.php | 18 ++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cdn_ui/src/Form/CdnSettingsForm.php b/cdn_ui/src/Form/CdnSettingsForm.php index a2be3ff..d2b4e73 100644 --- a/cdn_ui/src/Form/CdnSettingsForm.php +++ b/cdn_ui/src/Form/CdnSettingsForm.php @@ -24,7 +24,7 @@ class CdnSettingsForm extends ValidatableConfigFormBase { protected $streamWrapperManager; /** - * @inheritDoc + * {@inheritdoc} */ public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, StreamWrapperManagerInterface $streamWrapperManager) { parent::__construct($config_factory, $typed_config_manager); @@ -269,7 +269,7 @@ class CdnSettingsForm extends ValidatableConfigFormBase { // Vertical tab: 'Status'. $config->set('status', (bool) $form_state->getValue('status')); - // Vertical tab: 'Additional stream wrappers'. + // Vertical tab: 'Stream wrappers'. $stream_wrappers = array_values(array_filter($form_state->getValue(['wrappers', 'stream_wrappers']))); // Ensure 'public://' is always enabled, and ensure it's always first. $stream_wrappers = array_merge(['public'], $stream_wrappers); diff --git a/src/CdnSettings.php b/src/CdnSettings.php index f2c4a25..c5e011a 100644 --- a/src/CdnSettings.php +++ b/src/CdnSettings.php @@ -82,7 +82,8 @@ class CdnSettings { /** * Returns CDN-eligible stream wrappers. * - * @return string[] The allowed stream wrapper scheme names. + * @return string[] + * The allowed stream wrapper scheme names. */ public function getStreamWrappers() { $stream_wrappers = $this->rawSettings->get('stream_wrappers'); diff --git a/src/File/FileUrlGenerator.php b/src/File/FileUrlGenerator.php index 92bc654..67439f1 100644 --- a/src/File/FileUrlGenerator.php +++ b/src/File/FileUrlGenerator.php @@ -122,34 +122,32 @@ class FileUrlGenerator { return FALSE; } - // When farfuture is enabled, rewrite the file URL to let Drupal serve the - // file with optimal headers. Only possible if the file exists. if (!$scheme = $this->fileSystem->uriScheme($uri)) { $scheme = self::RELATIVE; // A relative URL for a file contains '%20' instead of spaces. A relative // file path contains spaces. - $filePath = $relative_url = '/' . $uri; - $realFile = $this->root . rawurldecode($relative_url);; + $file_path = $relative_url = '/' . $uri; + $real_file = $this->root . rawurldecode($relative_url);; } else { - $fileUri = $realFile = $uri; - $filePath = '/' . substr($fileUri, strlen($scheme . '://')); + $file_uri = $real_file = $uri; + $file_path = '/' . substr($file_uri, strlen($scheme . '://')); $relative_url = str_replace($this->requestStack->getCurrentRequest()->getSchemeAndHttpHost() . $this->getBasePath(), '', $this->streamWrapperManager->getViaUri($uri)->getExternalUrl()); } // When farfuture is enabled, rewrite the file URL to let Drupal serve the // file with optimal headers. Only possible if the file exists. - if ($this->settings->farfutureIsEnabled() && file_exists($realFile)) { + if ($this->settings->farfutureIsEnabled() && file_exists($real_file)) { // We do the filemtime() call separately, because a failed filemtime() // will cause a PHP warning to be written to the log, which would remove // any performance gain achieved by removing the file_exists() call. - $mtime = filemtime($realFile); + $mtime = filemtime($real_file); // Generate a security token. Ensures that users can not request any // file they want by manipulating the URL (they could otherwise request // settings.php for example). See https://www.drupal.org/node/1441502. - $calculated_token = Crypt::hmacBase64($mtime . $scheme . UrlHelper::encodePath($filePath), $this->privateKey->get() . Settings::getHashSalt()); - return '//' . $cdn_domain . $this->getBasePath() . '/cdn/ff/' . $calculated_token . '/' . $mtime . '/' . $scheme . $filePath; + $calculated_token = Crypt::hmacBase64($mtime . $scheme . UrlHelper::encodePath($file_path), $this->privateKey->get() . Settings::getHashSalt()); + return '//' . $cdn_domain . $this->getBasePath() . '/cdn/ff/' . $calculated_token . '/' . $mtime . '/' . $scheme . $file_path; } return '//' . $cdn_domain . $this->getBasePath() . $relative_url;