class FlysystemServiceProvider in Flysystem 8
Same name and namespace in other branches
- 3.x src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider
- 2.0.x src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider
- 3.0.x src/FlysystemServiceProvider.php \Drupal\flysystem\FlysystemServiceProvider
Flysystem dependency injection container.
Hierarchy
- class \Drupal\flysystem\FlysystemServiceProvider implements ServiceProviderInterface uses SchemeExtensionTrait
Expanded class hierarchy of FlysystemServiceProvider
1 file declares its use of FlysystemServiceProvider
- FlysystemServiceProviderTest.php in tests/
src/ Unit/ FlysystemServiceProviderTest.php
File
- src/
FlysystemServiceProvider.php, line 13
Namespace
Drupal\flysystemView source
class FlysystemServiceProvider implements ServiceProviderInterface {
use SchemeExtensionTrait;
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
$this
->swapDumper($container, 'js');
$this
->swapDumper($container, 'css');
foreach (Settings::get('flysystem', []) as $scheme => $settings) {
// Just some sanity checking, so things don't explode.
if (empty($settings['driver'])) {
continue;
}
$container
->register('flysystem_stream_wrapper.' . $scheme, 'Drupal\\flysystem\\FlysystemBridge')
->addTag('stream_wrapper', [
'scheme' => $scheme,
]);
// Register the path processors for local files.
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);
}
}
}
/**
* Swaps the js/css dumper if a scheme is configured to serve it.
*
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
* The container.
* @param string $extension
* The file extension to swap.
*/
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');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlysystemServiceProvider:: |
public | function |
Registers services to the container. Overrides ServiceProviderInterface:: |
|
FlysystemServiceProvider:: |
protected | function | Swaps the js/css dumper if a scheme is configured to serve it. | |
SchemeExtensionTrait:: |
public | function | Returns the scheme that should serve an extension. |