Browse Source

Make duplicate route simpler to find.

Instead of relying on row highlighting, bubble the duplicate route
into its own table at the top.

Refs #9237
Mark Story 9 years ago
parent
commit
01b32f122b
2 changed files with 16 additions and 21 deletions
  1. 3 1
      src/Routing/RouteCollection.php
  2. 13 20
      src/Template/Error/duplicate_named_route.ctp

+ 3 - 1
src/Routing/RouteCollection.php

@@ -79,9 +79,11 @@ class RouteCollection
         // 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;

+ 13 - 20
src/Template/Error/duplicate_named_route.ctp

@@ -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() ?>