Created
January 24, 2013 13:37
-
-
Save davedevelopment/4621669 to your computer and use it in GitHub Desktop.
Route finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| $app = require __DIR__ . '/../app/bootstrap.php'; | |
| $routes = $app['routes']->all(); | |
| $data = array(); | |
| foreach($routes as $route) { | |
| $d = array( | |
| 'method' => $route->getRequirement('_method'), | |
| 'pattern' => $route->getPattern(), | |
| ); | |
| if (is_string($route->getDefault('_controller'))) { | |
| $d['file'] = $route->getDefault('_controller'); | |
| $d['line'] = ''; | |
| } else { | |
| $cr = new ReflectionFunction($route->getDefault('_controller')); | |
| $d['file'] = str_replace(dirname(__DIR__) . '/', '', $cr->getFileName()); | |
| $d['line'] = $cr->getStartLine(); | |
| } | |
| $data[] = $d; | |
| } | |
| usort($data, function($a, $b) { | |
| return strcasecmp($a['pattern'], $b['pattern']); | |
| }); | |
| $maxlength = array( | |
| 'method' => 0, | |
| 'pattern' => 0, | |
| 'file' => 0, | |
| 'line' => 0, | |
| ); | |
| foreach($data as $d) { | |
| foreach ($d as $k => $v) { | |
| if (strlen($v) > $maxlength[$k]) { | |
| $maxlength[$k] = strlen($v); | |
| } | |
| } | |
| } | |
| foreach ($data as $d) { | |
| echo sprintf("%{$maxlength['method']}s %-{$maxlength['pattern']}s => %s:%d\n", | |
| $d['method'], | |
| $d['pattern'], | |
| $d['file'], | |
| $d['line'] | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment