RouteBuilder.php 1.4 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Definition of Drupal\Core\Routing\RouteBuilder.
 */

8 9 10 11 12 13 14 15 16 17 18 19 20 21
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 {

22 23 24 25 26
  /**
   * The dumper to which we should send collected routes.
   *
   * @var \Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface
   */
27 28
  protected $dumper;

29
  /**
30
   * Construcs the RouteBuilder using the passed MatcherDumperInterface.
31 32 33 34
   *
   * @param Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface $dumper
   *   The matcher dumper used to store the route information.
   */
35 36 37 38
  public function __construct(MatcherDumperInterface $dumper) {
    $this->dumper = $dumper;
  }

39 40 41
  /**
   * Rebuilds the route info and dumps to dumper.
   */
42 43 44 45 46 47 48 49 50 51 52 53 54
  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));
    }
  }

}