FlysystemServiceProvider.php in Flysystem 2.0.x
File
src/FlysystemServiceProvider.php
View source
<?php
namespace Drupal\flysystem;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\Site\Settings;
use Drupal\flysystem\Asset\SchemeExtensionTrait;
class FlysystemServiceProvider implements ServiceProviderInterface {
use SchemeExtensionTrait;
public function register(ContainerBuilder $container) {
$this
->swapDumper($container, 'js');
$this
->swapDumper($container, 'css');
foreach (Settings::get('flysystem', []) as $scheme => $settings) {
if (empty($settings['driver'])) {
continue;
}
$container
->register('flysystem_stream_wrapper.' . $scheme, 'Drupal\\flysystem\\FlysystemBridge')
->addTag('stream_wrapper', [
'scheme' => $scheme,
]);
if ($settings['driver'] === 'local' && !empty($settings['config']['public'])) {
$container
->register('flysystem.' . $scheme . '.path_processor', 'Drupal\\flysystem\\PathProcessor\\LocalPathProcessor')
->addTag('path_processor_inbound', [
'priority' => 400,
])
->addArgument($scheme);
}
}
}
protected function swapDumper(ContainerBuilder $container, $extension) {
if (!$container
->has('asset.' . $extension . '.dumper')) {
return;
}
if (!$container
->has('asset.' . $extension . '.collection_optimizer')) {
return;
}
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');
}
}
}