Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Routing / RouteProviderLazyBuilder.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
6 use Symfony\Component\HttpFoundation\Request;
7
8 /**
9  * A Route Provider front-end for all Drupal-stored routes.
10  */
11 class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
12
13   /**
14    * The route provider service.
15    *
16    * @var \Drupal\Core\Routing\RouteProviderInterface
17    */
18   protected $routeProvider;
19
20   /**
21    * The route building service.
22    *
23    * @var \Drupal\Core\Routing\RouteBuilderInterface
24    */
25   protected $routeBuilder;
26
27   /**
28    * Flag to determine if the router has been rebuilt.
29    *
30    * @var bool
31    */
32   protected $rebuilt = FALSE;
33
34   /**
35    * RouteProviderLazyBuilder constructor.
36    *
37    * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
38    *   The route provider service.
39    * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
40    *   The route building service.
41    */
42   public function __construct(RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder) {
43     $this->routeProvider = $route_provider;
44     $this->routeBuilder = $route_builder;
45   }
46
47   /**
48    * Gets the real route provider service and rebuilds the router id necessary.
49    *
50    * @return \Drupal\Core\Routing\RouteProviderInterface
51    *   The route provider service.
52    */
53   protected function getRouteProvider() {
54     if (!$this->rebuilt) {
55       $this->routeBuilder->rebuild();
56       $this->rebuilt = TRUE;
57     }
58     return $this->routeProvider;
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function getRouteCollectionForRequest(Request $request) {
65     return $this->getRouteProvider()->getRouteCollectionForRequest($request);
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function getRouteByName($name) {
72     return $this->getRouteProvider()->getRouteByName($name);
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function preLoadRoutes($names) {
79     return $this->getRouteProvider()->preLoadRoutes($names);
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function getRoutesByNames($names) {
86     return $this->getRouteProvider()->getRoutesByNames($names);
87   }
88
89   /**
90    * {@inheritdoc}
91    */
92   public function getRoutesByPattern($pattern) {
93     return $this->getRouteProvider()->getRoutesByPattern($pattern);
94   }
95
96   /**
97    * {@inheritdoc}
98    */
99   public function getAllRoutes() {
100     return $this->getRouteProvider()->getAllRoutes();
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   public function reset() {
107     // Don't call getRouteProvider as this is results in recursive rebuilds.
108     return $this->routeProvider->reset();
109   }
110
111   /**
112    * {@inheritdoc}
113    */
114   public function getRoutesPaged($offset, $length = NULL) {
115     return $this->getRouteProvider()->getRoutesPaged($offset, $length);
116   }
117
118   /**
119    * {@inheritdoc}
120    */
121   public function getRoutesCount() {
122     return $this->getRouteProvider()->getRoutesCount();
123   }
124
125   /**
126    * Determines if the router has been rebuilt.
127    *
128    * @return bool
129    *   TRUE is the router has been rebuilt, FALSE if not.
130    */
131   public function hasRebuilt() {
132     return $this->rebuilt;
133   }
134
135 }