Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/image/src/Routing/ImageStyleRoutes.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\image\Routing; | |
4 | |
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
6 use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; | |
7 use Symfony\Component\DependencyInjection\ContainerInterface; | |
8 use Symfony\Component\Routing\Route; | |
9 | |
10 /** | |
11 * Defines a route subscriber to register a url for serving image styles. | |
12 */ | |
13 class ImageStyleRoutes implements ContainerInjectionInterface { | |
14 | |
15 /** | |
16 * The stream wrapper manager service. | |
17 * | |
18 * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface | |
19 */ | |
20 protected $streamWrapperManager; | |
21 | |
22 /** | |
23 * Constructs a new ImageStyleRoutes object. | |
24 * | |
25 * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager | |
26 * The stream wrapper manager service. | |
27 */ | |
28 public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) { | |
29 $this->streamWrapperManager = $stream_wrapper_manager; | |
30 } | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 public static function create(ContainerInterface $container) { | |
36 return new static( | |
37 $container->get('stream_wrapper_manager') | |
38 ); | |
39 } | |
40 | |
41 /** | |
42 * Returns an array of route objects. | |
43 * | |
44 * @return \Symfony\Component\Routing\Route[] | |
45 * An array of route objects. | |
46 */ | |
47 public function routes() { | |
48 $routes = []; | |
49 // Generate image derivatives of publicly available files. If clean URLs are | |
50 // disabled image derivatives will always be served through the menu system. | |
51 // If clean URLs are enabled and the image derivative already exists, PHP | |
52 // will be bypassed. | |
53 $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath(); | |
54 | |
55 $routes['image.style_public'] = new Route( | |
56 '/' . $directory_path . '/styles/{image_style}/{scheme}', | |
57 [ | |
58 '_controller' => 'Drupal\image\Controller\ImageStyleDownloadController::deliver', | |
59 ], | |
60 [ | |
61 '_access' => 'TRUE', | |
62 ] | |
63 ); | |
64 return $routes; | |
65 } | |
66 | |
67 } |