You are here

class AuthcacheP13nDefaultRequestRouter in Authenticated User Page Caching (Authcache) 7.2

Interface for mapping URLs to requests and vice versa.

Hierarchy

Expanded class hierarchy of AuthcacheP13nDefaultRequestRouter

7 string references to 'AuthcacheP13nDefaultRequestRouter'
AuthcacheP13nDefaultRequestRouter::generateURL in modules/authcache_p13n/includes/AuthcacheP13nDefaultRequestRouter.inc
Given a request id and an optional argument, return the appropriate URL.
AuthcacheP13nDefaultRequestRouter::getHandler in modules/authcache_p13n/includes/AuthcacheP13nDefaultRequestRouter.inc
Return an instance of AuthcacheP13nRequestHandlerInterface.
AuthcacheP13nDefaultRequestRouter::rebuild in modules/authcache_p13n/includes/AuthcacheP13nDefaultRequestRouter.inc
Rebuild the routing information after configuration changes.
AuthcacheP13nTestDefaultRequestRouter::setUp in modules/authcache_p13n/tests/authcache_p13n.frontcontroller.test
Sets up a Drupal site for running functional and integration tests.
authcache_p13n_admin_routes in modules/authcache_p13n/authcache_p13n.admin.inc
Display a list of available routes and frontcontroller settings.

... See full list

File

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

View source
class AuthcacheP13nDefaultRequestRouter implements AuthcacheP13nRequestRouterInterface {

  /**
   * Key-value collection id for handlers.
   */
  const HANDLER_COLLECTION = 'route_handlers';

  /**
   * Key-value collection id for url generators.
   */
  const URL_GENERATOR_COLLECTION = 'route_generators';

  /**
   * {@inheritdoc}
   */
  public function getRoutes() {
    return $this
      ->getHandlerStore()
      ->getKeys();
  }

  /**
   * {@inheritdoc}
   */
  public function getHandler($route_id) {
    $handler = $this
      ->getHandlerStore()
      ->getOne($route_id);
    if (!$handler) {
      watchdog('AuthcacheP13nDefaultRequestRouter', 'Failed to find request handler for route %r', array(
        '%r' => $route_id,
      ), WATCHDOG_ERROR);
    }
    return $handler;
  }

  /**
   * {@inheritdoc}
   */
  public function generateURL($route_id, $arg = NULL) {
    $generator = $this
      ->getUrlGeneratorStore()
      ->getOne($route_id);
    if ($generator) {
      return $generator
        ->url($route_id, $arg);
    }
    else {
      watchdog('AuthcacheP13nDefaultRequestRouter', 'Failed to find url generator for route %r', array(
        '%r' => $route_id,
      ), WATCHDOG_ERROR);
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

  /**
   * Map of short type name constants to key-value store.
   */
  protected $handlerStore;

  /**
   * Map of short type name constants to key-value store.
   */
  protected $urlGeneratorStore;

  /**
   * Return new key value store for pre-built request handlers.
   */
  protected function getHandlerStore() {
    if (!isset($this->handlerStore)) {
      $this->handlerStore = new AuthcacheP13nDatabaseKeyValueStore(static::HANDLER_COLLECTION);
    }
    return $this->handlerStore;
  }

  /**
   * Return new key value store for pre-built request handlers.
   */
  protected function getUrlGeneratorStore() {
    if (!isset($this->urlGeneratorStore)) {
      $this->urlGeneratorStore = new AuthcacheP13nDatabaseKeyValueStore(static::URL_GENERATOR_COLLECTION);
    }
    return $this->urlGeneratorStore;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthcacheP13nDefaultRequestRouter::$handlerStore protected property Map of short type name constants to key-value store.
AuthcacheP13nDefaultRequestRouter::$urlGeneratorStore protected property Map of short type name constants to key-value store.
AuthcacheP13nDefaultRequestRouter::generateURL public function Given a request id and an optional argument, return the appropriate URL. Overrides AuthcacheP13nRequestRouterInterface::generateURL
AuthcacheP13nDefaultRequestRouter::getHandler public function Return an instance of AuthcacheP13nRequestHandlerInterface. Overrides AuthcacheP13nRequestRouterInterface::getHandler
AuthcacheP13nDefaultRequestRouter::getHandlerStore protected function Return new key value store for pre-built request handlers.
AuthcacheP13nDefaultRequestRouter::getRoutes public function Return a list of existing route ids. Overrides AuthcacheP13nRequestRouterInterface::getRoutes
AuthcacheP13nDefaultRequestRouter::getUrlGeneratorStore protected function Return new key value store for pre-built request handlers.
AuthcacheP13nDefaultRequestRouter::HANDLER_COLLECTION constant Key-value collection id for handlers.
AuthcacheP13nDefaultRequestRouter::rebuild public function Rebuild the routing information after configuration changes. Overrides AuthcacheP13nRequestRouterInterface::rebuild
AuthcacheP13nDefaultRequestRouter::URL_GENERATOR_COLLECTION constant Key-value collection id for url generators.