public function MatcherDumper::dump

Dumps a set of routes to the router table in the database.

Available options:

  • route_set: The route grouping that is being dumped. All existing routes with this route set will be deleted on dump.
  • base_class: The base class name.

Parameters

array $options: An array of options.

Overrides MatcherDumperInterface::dump

File

drupal/core/lib/Drupal/Core/Routing/MatcherDumper.php, line 87
Definition of Drupal\Core\Routing\MatcherDumper.

Class

MatcherDumper
Dumps Route information to a database table.

Namespace

Drupal\Core\Routing

Code

public function dump(array $options = array()) {
  $options += array(
    'route_set' => '',
  );

  // Convert all of the routes into database records.
  $insert = $this->connection
    ->insert($this->tableName)
    ->fields(array(
    'name',
    'route_set',
    'fit',
    'pattern',
    'pattern_outline',
    'number_parts',
    'route',
  ));
  foreach ($this->routes as $name => $route) {
    $route
      ->setOption('compiler_class', '\\Drupal\\Core\\Routing\\RouteCompiler');
    $compiled = $route
      ->compile();
    $values = array(
      'name' => $name,
      'route_set' => $options['route_set'],
      'fit' => $compiled
        ->getFit(),
      'pattern' => $compiled
        ->getPattern(),
      'pattern_outline' => $compiled
        ->getPatternOutline(),
      'number_parts' => $compiled
        ->getNumParts(),
      'route' => serialize($route),
    );
    $insert
      ->values($values);
  }

  // Delete any old records in this route set first, then insert the new ones.
  // That avoids stale data. The transaction makes it atomic to avoid
  // unstable router states due to random failures.
  $txn = $this->connection
    ->startTransaction();
  $this->connection
    ->delete($this->tableName)
    ->condition('route_set', $options['route_set'])
    ->execute();
  $insert
    ->execute();

  // We want to reuse the dumper for multiple route sets, so on dump, flush
  // the queued routes.
  $this->routes = NULL;

  // Transaction ends here.
}