630e81ffe26bfd2703fcb5e1e50c2c980d30d5e8
[yaffs-website] / web / core / lib / Drupal / Core / Routing / NullGenerator.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 use Drupal\Core\Render\BubbleableMetadata;
6 use Symfony\Component\HttpFoundation\RequestStack;
7 use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
8 use Symfony\Component\Routing\Exception\RouteNotFoundException;
9 use Symfony\Component\Routing\Route;
10
11 /**
12  * No-op implementation of a Url Generator, needed for backward compatibility.
13  */
14 class NullGenerator extends UrlGenerator {
15
16   /**
17    * Override the parent constructor.
18    *
19    * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
20    *   The request stack.
21    */
22   public function __construct(RequestStack $request_stack) {
23     $this->requestStack = $request_stack;
24     $this->context = new RequestContext();
25   }
26
27   /**
28    * {@inheritdoc}
29    *
30    * Methods generate(), generateFromRoute() and getPathFromRoute() all call
31    * this protected method.
32    */
33   protected function getRoute($name) {
34     if ($name === '<front>') {
35       return new Route('/');
36     }
37     elseif ($name === '<current>') {
38       return new Route($this->requestStack->getCurrentRequest()->getPathInfo());
39     }
40     elseif ($name === '<none>') {
41       return new Route('');
42     }
43     throw new RouteNotFoundException();
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   protected function processRoute($name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   protected function getInternalPathFromRoute($name, Route $route, $parameters = [], &$query_params = []) {
56     return $route->getPath();
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function setContext(SymfonyRequestContext $context) {
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getContext() {
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   protected function processPath($path, &$options = [], BubbleableMetadata $bubbleable_metadata = NULL) {
75     return $path;
76   }
77
78 }