comparison core/lib/Drupal/Core/Asset/JsCollectionOptimizer.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
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Core\Asset; 3 namespace Drupal\Core\Asset;
4 4
5 use Drupal\Core\File\FileSystemInterface;
5 use Drupal\Core\State\StateInterface; 6 use Drupal\Core\State\StateInterface;
6 7
7 /** 8 /**
8 * Optimizes JavaScript assets. 9 * Optimizes JavaScript assets.
9 */ 10 */
34 * The state key/value store. 35 * The state key/value store.
35 * 36 *
36 * @var \Drupal\Core\State\StateInterface 37 * @var \Drupal\Core\State\StateInterface
37 */ 38 */
38 protected $state; 39 protected $state;
40
41 /**
42 * The file system service.
43 *
44 * @var \Drupal\Core\File\FileSystemInterface
45 */
46 protected $fileSystem;
39 47
40 /** 48 /**
41 * Constructs a JsCollectionOptimizer. 49 * Constructs a JsCollectionOptimizer.
42 * 50 *
43 * @param \Drupal\Core\Asset\AssetCollectionGrouperInterface $grouper 51 * @param \Drupal\Core\Asset\AssetCollectionGrouperInterface $grouper
46 * The optimizer for a single JS asset. 54 * The optimizer for a single JS asset.
47 * @param \Drupal\Core\Asset\AssetDumperInterface $dumper 55 * @param \Drupal\Core\Asset\AssetDumperInterface $dumper
48 * The dumper for optimized JS assets. 56 * The dumper for optimized JS assets.
49 * @param \Drupal\Core\State\StateInterface $state 57 * @param \Drupal\Core\State\StateInterface $state
50 * The state key/value store. 58 * The state key/value store.
51 */ 59 * @param \Drupal\Core\File\FileSystemInterface $file_system
52 public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state) { 60 * The file system service.
61 */
62 public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state, FileSystemInterface $file_system = NULL) {
53 $this->grouper = $grouper; 63 $this->grouper = $grouper;
54 $this->optimizer = $optimizer; 64 $this->optimizer = $optimizer;
55 $this->dumper = $dumper; 65 $this->dumper = $dumper;
56 $this->state = $state; 66 $this->state = $state;
67 if (!$file_system) {
68 @trigger_error('The file_system service must be passed to JsCollectionOptimizer::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED);
69 $file_system = \Drupal::service('file_system');
70 }
71 $this->fileSystem = $file_system;
57 } 72 }
58 73
59 /** 74 /**
60 * {@inheritdoc} 75 * {@inheritdoc}
61 * 76 *
178 public function deleteAll() { 193 public function deleteAll() {
179 $this->state->delete('system.js_cache_files'); 194 $this->state->delete('system.js_cache_files');
180 $delete_stale = function ($uri) { 195 $delete_stale = function ($uri) {
181 // Default stale file threshold is 30 days. 196 // Default stale file threshold is 30 days.
182 if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { 197 if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) {
183 file_unmanaged_delete($uri); 198 $this->fileSystem->delete($uri);
184 } 199 }
185 }; 200 };
186 file_scan_directory('public://js', '/.*/', ['callback' => $delete_stale]); 201 file_scan_directory('public://js', '/.*/', ['callback' => $delete_stale]);
187 } 202 }
188 203