Move router rebuilding into an object so we can break it up more easily.

8.0.x
Larry Garfield 2012-09-02 12:46:29 -05:00 committed by effulgentsia
parent 404e74e187
commit f6bf963097
3 changed files with 38 additions and 17 deletions

View File

@ -6830,7 +6830,7 @@ function drupal_flush_all_caches() {
// Rebuild the menu router based on all rebuilt data.
// Important: This rebuild must happen last, so the menu router is guaranteed
// to be based on up to date information.
router_rebuild();
drupal_container()->get('router.builder')->rebuild();
menu_router_rebuild();
// Re-initialize the maintenance theme, if the current request attempted to
@ -6842,22 +6842,6 @@ function drupal_flush_all_caches() {
}
}
function router_rebuild() {
// We need to manually call each module so that we can know which module
// a given item came from.
$dumper = drupal_container()->get('router.dumper', Container::NULL_ON_INVALID_REFERENCE);
if ($dumper) {
foreach (module_implements('route_info') as $module) {
$routes = call_user_func($module . '_route_info');
drupal_alter('router_info', $routes, $module);
$dumper->addRoutes($routes);
$dumper->dump(array('route_set' => $module));
}
}
}
/**
* Changes the dummy query string added to all CSS and JavaScript files.
*

View File

@ -58,6 +58,8 @@ class CoreBundle extends Bundle
$container->register('router.dumper', '\Drupal\Core\Routing\MatcherDumper')
->addArgument(new Reference('database'));
$container->register('router.builder', 'Drupal\Core\Routing\RouteBuilder')
->addArgument(new Reference('router.dumper'));
// @todo Replace below lines with the commented out block below it when it's
// performant to do so: http://drupal.org/node/1706064.

View File

@ -0,0 +1,35 @@
<?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;
public function __construct(MatcherDumperInterface $dumper) {
$this->dumper = $dumper;
}
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));
}
}
}