You are here

protected function FlysystemServiceProvider::swapDumper in Flysystem 3.x

Same name and namespace in other branches
  1. 8 src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider::swapDumper()
  2. 2.0.x src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider::swapDumper()
  3. 3.0.x src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider::swapDumper()

Swaps the js/css dumper if a scheme is configured to serve it.

Parameters

\Drupal\Core\DependencyInjection\ContainerBuilder $container: The container.

string $extension: The file extension to swap.

1 call to FlysystemServiceProvider::swapDumper()
FlysystemServiceProvider::register in src/FlysystemServiceProvider.php
Registers services to the container.

File

src/FlysystemServiceProvider.php, line 54

Class

FlysystemServiceProvider
Flysystem dependency injection container.

Namespace

Drupal\flysystem

Code

protected function swapDumper(ContainerBuilder $container, $extension) {
  if (!$container
    ->has('asset.' . $extension . '.dumper')) {
    return;
  }
  if (!$container
    ->has('asset.' . $extension . '.collection_optimizer')) {
    return;
  }

  // Don't rewrite if there's nothing to change.
  if ($this
    ->getSchemeForExtension($extension) === 'public') {
    return;
  }
  $container
    ->getDefinition('asset.' . $extension . '.dumper')
    ->setClass('Drupal\\flysystem\\Asset\\AssetDumper');
  $container
    ->getDefinition('asset.' . $extension . '.collection_optimizer')
    ->setClass('Drupal\\flysystem\\Asset\\' . ucfirst($extension) . 'CollectionOptimizer');
  if ($extension === 'css') {
    $container
      ->getDefinition('asset.css.optimizer')
      ->setClass('Drupal\\flysystem\\Asset\\CssOptimizer');
  }
}