RouteBuilder.php 1.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php

namespace Drupal\Core\Routing;

use Symfony\Component\Routing\RouteCompilerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;

/**
 * Managing class for rebuilding the router table.
 *
 * Because this class makes use of the modules system, it cannot currently
 * be unit tested.
 */
class RouteBuilder {

  protected $dumper;

19 20 21 22 23 24
  /**
   * Construcs the RouteBuilder using the passed MatcherDumperInterface
   *
   * @param Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface $dumper
   *   The matcher dumper used to store the route information.
   */
25 26 27 28
  public function __construct(MatcherDumperInterface $dumper) {
    $this->dumper = $dumper;
  }

29 30 31
  /**
   * Rebuilds the route info and dumps to dumper.
   */
32 33 34 35 36 37 38 39 40 41 42 43 44
  public function rebuild() {
    // We need to manually call each module so that we can know which module
    // a given item came from.

    foreach (module_implements('route_info') as $module) {
      $routes = call_user_func($module . '_route_info');
      drupal_alter('router_info', $routes, $module);
      $this->dumper->addRoutes($routes);
      $this->dumper->dump(array('route_set' => $module));
    }
  }

}