Drupal 8  8.0.2
CssCollectionOptimizer Class Reference
Inheritance diagram for CssCollectionOptimizer:

Public Member Functions

 __construct (AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state)
 
 optimize (array $css_assets)
 
 getAll ()
 
 deleteAll ()
 

Protected Member Functions

 generateHash (array $css_group)
 

Protected Attributes

 $grouper
 
 $optimizer
 
 $dumper
 
 $state
 

Detailed Description

Optimizes CSS assets.

Constructor & Destructor Documentation

__construct ( AssetCollectionGrouperInterface  $grouper,
AssetOptimizerInterface  $optimizer,
AssetDumperInterface  $dumper,
StateInterface  $state 
)

Constructs a CssCollectionOptimizer.

Parameters
\Drupal\Core\Asset\AssetCollectionGrouperInterfaceThe grouper for CSS assets.
\Drupal\Core\Asset\AssetOptimizerInterfaceThe optimizer for a single CSS asset.
\Drupal\Core\Asset\AssetDumperInterfaceThe dumper for optimized CSS assets.
\Drupal\Core\State\StateInterfaceThe state key/value store.

References Drupal\state().

Here is the call graph for this function:

Member Function Documentation

deleteAll ( )

{Deletes all optimized asset collections assets.}

Implements AssetCollectionOptimizerInterface.

References Drupal\config(), file_scan_directory(), file_unmanaged_delete(), and Drupal\state().

Here is the call graph for this function:

generateHash ( array  $css_group)
protected

Generate a hash for a given group of CSS assets.

Parameters
array$css_groupA group of CSS assets.
Returns
string A hash to uniquely identify the given group of CSS assets.

Referenced by CssCollectionOptimizer\optimize().

Here is the caller graph for this function:

getAll ( )

{Returns all optimized asset collections assets.

Returns
string[] URIs for all optimized asset collection assets.
}

Implements AssetCollectionOptimizerInterface.

References Drupal\state().

Here is the call graph for this function:

optimize ( array  $css_assets)

{Optimizes a collection of assets.

Parameters
array$assetsAn asset collection.
Returns
array An optimized asset collection.
}

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 there is no file name value for the key, which will happen if a new file name has been added to $css or after the lookup variable is emptied to force a rebuild of the cache. Second, the cache file is generated if it is missing on disk. Old cache files are not deleted immediately when the lookup variable is emptied, but are deleted after a configurable period (

system.performance.stale_file_threshold

) to ensure that files referenced by a cached page will still be available.

Implements AssetCollectionOptimizerInterface.

References CssCollectionOptimizer\generateHash(), and Drupal\state().

Here is the call graph for this function:


The documentation for this class was generated from the following file: