You are here

class JsCollectionOptimizer in Flysystem 2.0.x

Same name and namespace in other branches
  1. 8 src/Asset/JsCollectionOptimizer.php \Drupal\flysystem\Asset\JsCollectionOptimizer
  2. 3.x src/Asset/JsCollectionOptimizer.php \Drupal\flysystem\Asset\JsCollectionOptimizer
  3. 3.0.x src/Asset/JsCollectionOptimizer.php \Drupal\flysystem\Asset\JsCollectionOptimizer

Optimizes JavaScript assets.

Hierarchy

Expanded class hierarchy of JsCollectionOptimizer

2 files declare their use of JsCollectionOptimizer
CollectionOptimizerTest.php in tests/src/Kernel/CollectionOptimizerTest.php
FlysystemServiceProviderTest.php in tests/src/Unit/FlysystemServiceProviderTest.php

File

src/Asset/JsCollectionOptimizer.php, line 10

Namespace

Drupal\flysystem\Asset
View source
class JsCollectionOptimizer extends DrupalJsCollectionOptimizer {
  use SchemeExtensionTrait;

  /**
   * {@inheritdoc}
   */
  public function deleteAll() {
    $this->state
      ->delete('system.js_cache_files');

    /** @var \Drupal\Core\File\FileSystem $file_system */
    $file_system = \Drupal::service('file_system');
    $delete_stale = static function ($uri) use ($file_system) {

      // Default stale file threshold is 30 days (2592000 seconds).
      $stale_file_threshold = \Drupal::config('system.performance')
        ->get('stale_file_threshold') ?? 2592000;
      if (\Drupal::time()
        ->getRequestTime() - filemtime($uri) > $stale_file_threshold) {
        $file_system
          ->delete($uri);
      }
    };
    $js_dir = $this
      ->getSchemeForExtension('js') . '://js';
    if (is_dir($js_dir)) {
      $file_system
        ->scanDirectory($js_dir, '/.*/', [
        'callback' => $delete_stale,
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsCollectionOptimizer::$dumper protected property An asset dumper.
JsCollectionOptimizer::$fileSystem protected property The file system service.
JsCollectionOptimizer::$grouper protected property A JS asset grouper.
JsCollectionOptimizer::$optimizer protected property A JS asset optimizer.
JsCollectionOptimizer::$state protected property The state key/value store.
JsCollectionOptimizer::deleteAll public function Deletes all optimized asset collections assets. Overrides JsCollectionOptimizer::deleteAll
JsCollectionOptimizer::generateHash protected function Generate a hash for a given group of JavaScript assets.
JsCollectionOptimizer::getAll public function Returns all optimized asset collections assets. Overrides AssetCollectionOptimizerInterface::getAll
JsCollectionOptimizer::optimize public function The cache file name is retrieved on a page load via a lookup variable that contains an associative array. The array key is the hash of the names in $files while the value is the cache file name. The cache file is generated in two cases. First, if… Overrides AssetCollectionOptimizerInterface::optimize
JsCollectionOptimizer::__construct public function Constructs a JsCollectionOptimizer.
SchemeExtensionTrait::getSchemeForExtension public function Returns the scheme that should serve an extension.