You are here

public function AuthcacheP13nDefaultRequestRouter::rebuild in Authenticated User Page Caching (Authcache) 7.2

Rebuild the routing information after configuration changes.

Overrides AuthcacheP13nRequestRouterInterface::rebuild

File

modules/authcache_p13n/includes/AuthcacheP13nDefaultRequestRouter.inc, line 59
Defines the interface for mapping URLs to requests and vice versa.

Class

AuthcacheP13nDefaultRequestRouter
Interface for mapping URLs to requests and vice versa.

Code

public function rebuild() {

  // Collect all request definitions.
  $resources = authcache_p13n_request_resources();
  $processors = authcache_p13n_resource_processors();
  $handler_store = $this
    ->getHandlerStore();
  $url_generator_store = $this
    ->getUrlGeneratorStore();
  $obsolete_handlers = drupal_map_assoc($handler_store
    ->getKeys());
  $obsolete_url_generators = drupal_map_assoc($url_generator_store
    ->getKeys());
  foreach ($resources as $route_id => $resource) {
    try {
      $factory = new AuthcacheP13nObjectFactory($resource, $processors);
      $handler = $factory
        ->get('handler');
      $generator = $factory
        ->get('url generator');
      $handler_store
        ->set($route_id, $handler);
      $url_generator_store
        ->set($route_id, $generator);
      unset($obsolete_handlers[$route_id]);
      unset($obsolete_url_generators[$route_id]);
    } catch (Exception $e) {
      watchdog_exception('AuthcacheP13nDefaultRequestRouter', $e);
    }
  }
  if (!empty($obsolete_handlers)) {
    $handler_store
      ->delete($obsolete_handlers);
  }
  if (!empty($obsolete_url_generators)) {
    $handler_store
      ->delete($obsolete_url_generators);
  }
}