Skip to content

Commit

Permalink
Make duplicate route simpler to find.
Browse files Browse the repository at this point in the history
Instead of relying on row highlighting, bubble the duplicate route
into its own table at the top.

Refs #9237
  • Loading branch information
markstory committed Aug 19, 2016
1 parent a7ac286 commit 01b32f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/Routing/RouteCollection.php
Expand Up @@ -79,9 +79,11 @@ public function add(Route $route, array $options = [])
// Explicit names
if (isset($options['_name'])) {
if (isset($this->_named[$options['_name']])) {
$matched = $this->_named[$options['_name']];
throw new DuplicateNamedRouteException([
'name' => $options['_name'],
'url' => $this->_named[$options['_name']]->template
'url' => $matched->template,
'duplicate' => $matched,
]);
}
$this->_named[$options['_name']] = $route;
Expand Down
33 changes: 13 additions & 20 deletions src/Template/Error/duplicate_named_route.ctp
Expand Up @@ -42,28 +42,21 @@ Remove duplicate route names in your route configuration.</p>
</pre>
<?php endif; ?>

<h3>Connected Routes</h3>
<table cellspacing="0" cellpadding="0">
<tr><th>Template</th><th>Defaults</th><th>Options</th></tr>
<?php
$url = false;
if (!empty($attributes['url'])) {
$url = $attributes['url'];
}
foreach (Router::routes() as $route) :
if (isset($route->options['_name']) && $url === $route->options['_name']) :
echo '<tr class="error">';
else :
echo '<tr>';
endif;
<?php if (isset($attributes['duplicate'])): ?>
<h3>Duplicate Route</h3>
<table cellspacing="0" cellpadding="0">
<tr><th>Template</th><th>Defaults</th><th>Options</th></tr>
<?php
$other = $attributes['duplicate'];
echo '<tr>';
printf(
'<td width="25%%">%s</td><td>%s</td><td width="20%%">%s</td>',
$route->template,
Debugger::exportVar($route->defaults),
Debugger::exportVar($route->options)
$other->template,
Debugger::exportVar($other->defaults),
Debugger::exportVar($other->options)
);
echo '</tr>';
endforeach;
?>
</table>
?>
</table>
<?php endif; ?>
<?php $this->end() ?>

0 comments on commit 01b32f1

Please sign in to comment.