diff --git a/index.php b/index.php index a867cbe..f1b35bd 100644 --- a/index.php +++ b/index.php @@ -134,6 +134,17 @@ Route::add('/الرقص-العربي', function() { echo 'Arabic example. Non english letters should work too
'; }); +// Return example +// Returned data gets echoed +Route::add('/return', function() { + navi(); + return 'This text gets returned by the add method'; +}); + +// Arrow function example +// Note: You can use this example only if you are on PHP 7.4 or higher +// Route::add('/arrow/([a-z-0-9-]*)', fn($foo) => 'This is a working arrow function example. Parameter: '.$foo ); + // Trailing slash example Route::add('/aTrailingSlashDoesNotMatter', function() { navi(); diff --git a/src/Steampixel/Route.php b/src/Steampixel/Route.php index bc94adc..e864e21 100644 --- a/src/Steampixel/Route.php +++ b/src/Steampixel/Route.php @@ -57,9 +57,9 @@ class Route { } } } - + $path = urldecode($path); - + // Get current request method $method = $_SERVER['REQUEST_METHOD']; @@ -96,7 +96,9 @@ class Route { array_shift($matches); // Remove basepath } - call_user_func_array($route['function'], $matches); + if($return_value = call_user_func_array($route['function'], $matches)) { + echo $return_value; + } $route_match_found = true; @@ -107,7 +109,7 @@ class Route { } // Break the loop if the first found route is a match - if($route_match_found&&!$multimatch){ + if($route_match_found&&!$multimatch) { break; }