Created
December 13, 2015 17:16
-
-
Save enygma/ac51b3d68d61862449b5 to your computer and use it in GitHub Desktop.
Output Slim 3 routes to Invoke config (and grouping)
This file contains 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
<?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