8a120972483791ef74e42d1b8298921ebbe0bcd6
[yaffs-website] / src / PathProcessor / PathProcessorFiles.php
1 <?php
2
3 namespace Drupal\system\PathProcessor;
4
5 use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
6 use Symfony\Component\HttpFoundation\Request;
7
8 /**
9  * Defines a path processor to rewrite file URLs.
10  *
11  * As the route system does not allow arbitrary amount of parameters convert
12  * the file path to a query parameter on the request.
13  */
14 class PathProcessorFiles implements InboundPathProcessorInterface {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function processInbound($path, Request $request) {
20     if (strpos($path, '/system/files/') === 0 && !$request->query->has('file')) {
21       $file_path = preg_replace('|^\/system\/files\/|', '', $path);
22       $request->query->set('file', $file_path);
23       return '/system/files';
24     }
25     return $path;
26   }
27
28 }