Skip to content

Instantly share code, notes, and snippets.

@enygma
Created December 13, 2015 17:16
Show Gist options
  • Save enygma/ac51b3d68d61862449b5 to your computer and use it in GitHub Desktop.
Save enygma/ac51b3d68d61862449b5 to your computer and use it in GitHub Desktop.
Output Slim 3 routes to Invoke config (and grouping)
<?php
$routes = $app->getContainer()->get('router')->getRoutes();
$grouped = [];
foreach ($routes as $index => $route) {
$pattern = $route->getPattern();
preg_match('/\{.+?Id\}/', $pattern, $match);
if (isset($match[0])) {
$pattern = str_replace($match[0], '[0-9]+', $pattern);
}
echo $pattern.":\n protected:on\n";
// Assign them to groups
$parts = explode('/', $pattern);
if (isset($grouped[$parts[1]])) {
$grouped[$parts[1]][] = $pattern;
} else {
$grouped[$parts[1]] = [$pattern];
}
}
print_r($grouped);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment