Added return feature and arrow function example
This commit is contained in:
parent
66a6bbae95
commit
dbb63d3043
11
index.php
11
index.php
|
@ -134,6 +134,17 @@ Route::add('/الرقص-العربي', function() {
|
||||||
echo 'Arabic example. Non english letters should work too <br>';
|
echo 'Arabic example. Non english letters should work too <br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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
|
// Trailing slash example
|
||||||
Route::add('/aTrailingSlashDoesNotMatter', function() {
|
Route::add('/aTrailingSlashDoesNotMatter', function() {
|
||||||
navi();
|
navi();
|
||||||
|
|
|
@ -57,9 +57,9 @@ class Route {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = urldecode($path);
|
$path = urldecode($path);
|
||||||
|
|
||||||
// Get current request method
|
// Get current request method
|
||||||
$method = $_SERVER['REQUEST_METHOD'];
|
$method = $_SERVER['REQUEST_METHOD'];
|
||||||
|
|
||||||
|
@ -96,7 +96,9 @@ class Route {
|
||||||
array_shift($matches); // Remove basepath
|
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;
|
$route_match_found = true;
|
||||||
|
|
||||||
|
@ -107,7 +109,7 @@ class Route {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break the loop if the first found route is a match
|
// Break the loop if the first found route is a match
|
||||||
if($route_match_found&&!$multimatch){
|
if($route_match_found&&!$multimatch) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user