Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Routing / RouteProviderLazyBuilder.php
index 8c59900c82ff38b5f9deed5f97b50ffafd63e922..a2cb8c57851330c28545bd05fa136b6f36d52bf1 100644 (file)
@@ -3,12 +3,13 @@
 namespace Drupal\Core\Routing;
 
 use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
  * A Route Provider front-end for all Drupal-stored routes.
  */
-class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
+class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface {
 
   /**
    * The route provider service.
@@ -31,6 +32,18 @@ class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, Pag
    */
   protected $rebuilt = FALSE;
 
+  /**
+   * Flag to determine if router is currently being rebuilt.
+   *
+   * Used to prevent recursive router rebuilds during module installation.
+   * Recursive rebuilds can occur when route information is required by alter
+   * hooks that are triggered during a rebuild, for example,
+   * hook_menu_links_discovered_alter().
+   *
+   * @var bool
+   */
+  protected $rebuilding = FALSE;
+
   /**
    * RouteProviderLazyBuilder constructor.
    *
@@ -51,7 +64,7 @@ class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, Pag
    *   The route provider service.
    */
   protected function getRouteProvider() {
-    if (!$this->rebuilt) {
+    if (!$this->rebuilt && !$this->rebuilding) {
       $this->routeBuilder->rebuild();
       $this->rebuilt = TRUE;
     }
@@ -132,4 +145,27 @@ class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, Pag
     return $this->rebuilt;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events[RoutingEvents::DYNAMIC][] = ['routerRebuilding', 3000];
+    $events[RoutingEvents::FINISHED][] = ['routerRebuildFinished', -3000];
+    return $events;
+  }
+
+  /**
+   * Sets the router rebuilding flag to TRUE.
+   */
+  public function routerRebuilding() {
+    $this->rebuilding = TRUE;
+  }
+
+  /**
+   * Sets the router rebuilding flag to FALSE.
+   */
+  public function routerRebuildFinished() {
+    $this->rebuilding = FALSE;
+  }
+
 }