"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php" (26 Nov 2020, 4137 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "RouteProviderLazyBuilder.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    1 <?php
    2 
    3 namespace Drupal\Core\Routing;
    4 
    5 use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
    6 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    7 use Symfony\Component\HttpFoundation\Request;
    8 
    9 /**
   10  * A Route Provider front-end for all Drupal-stored routes.
   11  */
   12 class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface {
   13 
   14   /**
   15    * The route provider service.
   16    *
   17    * @var \Drupal\Core\Routing\RouteProviderInterface
   18    */
   19   protected $routeProvider;
   20 
   21   /**
   22    * The route building service.
   23    *
   24    * @var \Drupal\Core\Routing\RouteBuilderInterface
   25    */
   26   protected $routeBuilder;
   27 
   28   /**
   29    * Flag to determine if the router has been rebuilt.
   30    *
   31    * @var bool
   32    */
   33   protected $rebuilt = FALSE;
   34 
   35   /**
   36    * Flag to determine if router is currently being rebuilt.
   37    *
   38    * Used to prevent recursive router rebuilds during module installation.
   39    * Recursive rebuilds can occur when route information is required by alter
   40    * hooks that are triggered during a rebuild, for example,
   41    * hook_menu_links_discovered_alter().
   42    *
   43    * @var bool
   44    */
   45   protected $rebuilding = FALSE;
   46 
   47   /**
   48    * RouteProviderLazyBuilder constructor.
   49    *
   50    * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   51    *   The route provider service.
   52    * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
   53    *   The route building service.
   54    */
   55   public function __construct(RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder) {
   56     $this->routeProvider = $route_provider;
   57     $this->routeBuilder = $route_builder;
   58   }
   59 
   60   /**
   61    * Gets the real route provider service and rebuilds the router id necessary.
   62    *
   63    * @return \Drupal\Core\Routing\RouteProviderInterface
   64    *   The route provider service.
   65    */
   66   protected function getRouteProvider() {
   67     if (!$this->rebuilt && !$this->rebuilding) {
   68       $this->routeBuilder->rebuild();
   69       $this->rebuilt = TRUE;
   70     }
   71     return $this->routeProvider;
   72   }
   73 
   74   /**
   75    * {@inheritdoc}
   76    */
   77   public function getRouteCollectionForRequest(Request $request) {
   78     return $this->getRouteProvider()->getRouteCollectionForRequest($request);
   79   }
   80 
   81   /**
   82    * {@inheritdoc}
   83    */
   84   public function getRouteByName($name) {
   85     return $this->getRouteProvider()->getRouteByName($name);
   86   }
   87 
   88   /**
   89    * {@inheritdoc}
   90    */
   91   public function preLoadRoutes($names) {
   92     return $this->getRouteProvider()->preLoadRoutes($names);
   93   }
   94 
   95   /**
   96    * {@inheritdoc}
   97    */
   98   public function getRoutesByNames($names) {
   99     return $this->getRouteProvider()->getRoutesByNames($names);
  100   }
  101 
  102   /**
  103    * {@inheritdoc}
  104    */
  105   public function getRoutesByPattern($pattern) {
  106     return $this->getRouteProvider()->getRoutesByPattern($pattern);
  107   }
  108 
  109   /**
  110    * {@inheritdoc}
  111    */
  112   public function getAllRoutes() {
  113     return $this->getRouteProvider()->getAllRoutes();
  114   }
  115 
  116   /**
  117    * {@inheritdoc}
  118    */
  119   public function reset() {
  120     // Don't call getRouteProvider as this is results in recursive rebuilds.
  121     return $this->routeProvider->reset();
  122   }
  123 
  124   /**
  125    * {@inheritdoc}
  126    */
  127   public function getRoutesPaged($offset, $length = NULL) {
  128     return $this->getRouteProvider()->getRoutesPaged($offset, $length);
  129   }
  130 
  131   /**
  132    * {@inheritdoc}
  133    */
  134   public function getRoutesCount() {
  135     return $this->getRouteProvider()->getRoutesCount();
  136   }
  137 
  138   /**
  139    * Determines if the router has been rebuilt.
  140    *
  141    * @return bool
  142    *   TRUE is the router has been rebuilt, FALSE if not.
  143    */
  144   public function hasRebuilt() {
  145     return $this->rebuilt;
  146   }
  147 
  148   /**
  149    * {@inheritdoc}
  150    */
  151   public static function getSubscribedEvents() {
  152     $events[RoutingEvents::DYNAMIC][] = ['routerRebuilding', 3000];
  153     $events[RoutingEvents::FINISHED][] = ['routerRebuildFinished', -3000];
  154     return $events;
  155   }
  156 
  157   /**
  158    * Sets the router rebuilding flag to TRUE.
  159    */
  160   public function routerRebuilding() {
  161     $this->rebuilding = TRUE;
  162   }
  163 
  164   /**
  165    * Sets the router rebuilding flag to FALSE.
  166    */
  167   public function routerRebuildFinished() {
  168     $this->rebuilding = FALSE;
  169   }
  170 
  171 }