RemoteImageStyleRoutes.php in Remote Stream Wrapper 8
File
src/Routing/RemoteImageStyleRoutes.php
View source
<?php
namespace Drupal\remote_stream_wrapper\Routing;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
class RemoteImageStyleRoutes implements ContainerInjectionInterface {
protected $streamWrapperManager;
protected $moduleHandler;
public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager, ModuleHandlerInterface $module_handler) {
$this->streamWrapperManager = $stream_wrapper_manager;
$this->moduleHandler = $module_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('stream_wrapper_manager'), $container
->get('module_handler'));
}
public function routes() {
$routes = [];
if (!$this->moduleHandler
->moduleExists('image')) {
return $routes;
}
if (method_exists($this->streamWrapperManager, 'register')) {
$this->streamWrapperManager
->register();
}
$public_directory_path = $this->streamWrapperManager
->getViaScheme('public')
->getDirectoryPath();
$wrappers = $this->streamWrapperManager
->getWrappers();
$remote_wrappers = array_filter($wrappers, function ($wrapper) {
return file_is_wrapper_remote($wrapper['class']);
});
$remote_schemes = array_keys($remote_wrappers);
foreach ($remote_schemes as $scheme) {
$routes['image.style_' . $scheme] = new Route('/' . $public_directory_path . '/styles/{image_style}/' . $scheme, [
'_controller' => 'Drupal\\remote_stream_wrapper\\Controller\\RemoteImageStyleDownloadController::deliver',
'scheme' => $scheme,
'_disable_route_normalizer' => TRUE,
], [
'_access' => 'TRUE',
]);
}
return $routes;
}
}