Added method and examples for known routes

This commit is contained in:
SteamPixel 2021-02-08 11:14:14 +01:00
parent d7775a9fad
commit 7ff0f40ec1
2 changed files with 16 additions and 0 deletions

View File

@ -37,6 +37,7 @@ function navi() {
<li><a href="'.BASEPATH.'thecasedoesnotmatter">thecasedoesnotmatter</a></li> <li><a href="'.BASEPATH.'thecasedoesnotmatter">thecasedoesnotmatter</a></li>
<li><a href="'.BASEPATH.'this-route-is-not-defined">404 Test</a></li> <li><a href="'.BASEPATH.'this-route-is-not-defined">404 Test</a></li>
<li><a href="'.BASEPATH.'this-route-is-defined">405 Test</a></li> <li><a href="'.BASEPATH.'this-route-is-defined">405 Test</a></li>
<li><a href="'.BASEPATH.'known-routes">known routes</a></li>
</ul> </ul>
'; ';
} }
@ -201,6 +202,17 @@ Route::methodNotAllowed(function($path, $method) {
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!'; echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
}); });
// Return all known routes
Route::add('/known-routes', function() {
navi();
$routes = Route::getAll();
echo '<ul>';
foreach($routes as $route) {
echo '<li>'.$route['expression'].'</li>';
}
echo '</ul>';
});
// Run the Router with the given Basepath // Run the Router with the given Basepath
Route::run(BASEPATH); Route::run(BASEPATH);

View File

@ -23,6 +23,10 @@ class Route {
)); ));
} }
public static function getAll(){
return self::$routes;
}
public static function pathNotFound($function) { public static function pathNotFound($function) {
self::$pathNotFound = $function; self::$pathNotFound = $function;
} }