Dumps a set of routes to the router table in the database.
Available options:
array $options: An array of options.
Overrides MatcherDumperInterface::dump
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.
}