RouteProvider::preLoadRoutes

public RouteProvider::preLoadRoutes($names)

Pre-load routes by their names using the provided list of names.

This method exists in order to allow performance optimizations. It allows pre-loading serialized routes that may latter be retrieved using ::getRoutesByName()

Parameters

string[] $names: Array of route names to load.

Overrides PreloadableRouteProviderInterface::preLoadRoutes

File

core/lib/Drupal/Core/Routing/RouteProvider.php, line 196

Class

RouteProvider
A Route Provider front-end for all Drupal-stored routes.

Namespace

Drupal\Core\Routing

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public function preLoadRoutes($names) {
  if (empty($names)) {
    throw new \InvalidArgumentException('You must specify the route names to load');
  }
 
  $routes_to_load = array_diff($names, array_keys($this->routes), array_keys($this->serializedRoutes));
  if ($routes_to_load) {
 
    $cid = static::ROUTE_LOAD_CID_PREFIX . hash('sha512', serialize($routes_to_load));
    if ($cache = $this->cache->get($cid)) {
      $routes = $cache->data;
    }
    else {
      try {
        $result = $this->connection->query('SELECT name, route FROM {' . $this->connection->escapeTable($this->tableName) . '} WHERE name IN ( :names[] )', array(':names[]' => $routes_to_load));
        $routes = $result->fetchAllKeyed();
 
        $this->cache->set($cid, $routes, Cache::PERMANENT, ['routes']);
      }
      catch (\Exception $e) {
        $routes = [];
      }
    }
 
    $this->serializedRoutes += $routes;
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.