Mercurial > hg > cmmr2012-drupal-site
diff core/lib/Drupal/Core/Asset/AssetDumper.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Asset/AssetDumper.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/lib/Drupal/Core/Asset/AssetDumper.php Thu May 09 15:34:47 2019 +0100 @@ -3,6 +3,8 @@ namespace Drupal\Core\Asset; use Drupal\Component\Utility\Crypt; +use Drupal\Core\File\Exception\FileException; +use Drupal\Core\File\FileSystemInterface; /** * Dumps a CSS or JavaScript asset. @@ -10,6 +12,23 @@ class AssetDumper implements AssetDumperInterface { /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** + * AssetDumper constructor. + * + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file handler. + */ + public function __construct(FileSystemInterface $file_system = NULL) { + $this->fileSystem = $file_system; + } + + /** * {@inheritdoc} * * The file name for the CSS or JS cache file is generated from the hash of @@ -24,8 +43,13 @@ $path = 'public://' . $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)) { + $this->getFileSystem()->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY); + try { + if (!file_exists($uri) && !$this->getFileSystem()->saveData($data, $uri, FileSystemInterface::EXISTS_REPLACE)) { + return FALSE; + } + } + catch (FileException $e) { return FALSE; } // If CSS/JS gzip compression is enabled and the zlib extension is available @@ -37,11 +61,30 @@ // aren't working can set css.gzip to FALSE in order to skip // generating a file that won't be used. if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) { - if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { + try { + if (!file_exists($uri . '.gz') && !$this->getFileSystem()->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { + return FALSE; + } + } + catch (FileException $e) { return FALSE; } } return $uri; } + /** + * Helper method for returning the file system service. + * + * @return \Drupal\Core\File\FileSystemInterface + * The file system service. + */ + private function getFileSystem() { + if (!$this->fileSystem) { + @trigger_error('\Drupal\Core\File\FileSystemInterface is a dependency of this class in Drupal 8.7.0 and will be required before Drupal 9.0.0. See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED); + $this->fileSystem = \Drupal::service('file_system'); + } + return $this->fileSystem; + } + }