You are here

class CssCollectionOptimizer in Flysystem 3.0.x

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

Optimizes CSS assets.

Hierarchy

Expanded class hierarchy of CssCollectionOptimizer

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

File

src/Asset/CssCollectionOptimizer.php, line 10

Namespace

Drupal\flysystem\Asset
View source
class CssCollectionOptimizer extends DrupalCssCollectionOptimizer {
  use SchemeExtensionTrait;

  /**
   * {@inheritdoc}
   */
  public function deleteAll() {
    $this->state
      ->delete('drupal_css_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);
      }
    };
    $file_system
      ->scanDirectory($this
      ->getSchemeForExtension('css') . '://css', '/.*/', [
      'callback' => $delete_stale,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CssCollectionOptimizer::$dumper protected property An asset dumper.
CssCollectionOptimizer::$fileSystem protected property The file system service.
CssCollectionOptimizer::$grouper protected property A CSS asset grouper.
CssCollectionOptimizer::$optimizer protected property A CSS asset optimizer.
CssCollectionOptimizer::$state protected property The state key/value store.
CssCollectionOptimizer::deleteAll public function Deletes all optimized asset collections assets. Overrides CssCollectionOptimizer::deleteAll
CssCollectionOptimizer::generateHash protected function Generate a hash for a given group of CSS assets.
CssCollectionOptimizer::getAll public function Returns all optimized asset collections assets. Overrides AssetCollectionOptimizerInterface::getAll
CssCollectionOptimizer::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 file names in $css while the value is the cache file name. The cache file is generated in two cases. First, if… Overrides AssetCollectionOptimizerInterface::optimize
CssCollectionOptimizer::__construct public function Constructs a CssCollectionOptimizer.
SchemeExtensionTrait::getSchemeForExtension public function Returns the scheme that should serve an extension.