simpleDispatcher Deprecated
When I tried to use it, it was deprecated, what alternatives can I use? The README also uses it, so I suggest changing it up.
@Sam7367238 the functions are being replaced by this.
So, for simpleDispatcher you would do something like:
$routeDefinition = static function(FastRoute\ConfigureRoutes $r): void {
};
$dispatcher = \FastRoute\FastRoute::recommendedSettings($routeDefinition, __DIR__ . '/var/routes.cache')
->disableCache()
->dispatcher();
Documentation hasn't yet been updated to reflect that and we'll act on it.
Thanks for flagging it.
Well, I have this code
$dispatcher = simpleDispatcher(function(RouteCollector $routeCollector) {
$routes = include(BASE_PATH . "/routes/web.php");
foreach ($routes as $route) {
$routeCollector -> addRoute(...$route);
}
});
So how do I just sort of transition it into the code you provided?
The closure you're passing to simpleDispatcher() goes to the first variable I defined, and that's it.
I'd only advise not to disable the caching when running things in production 👍
Alright, how is this?
$routeDefinition = static function(RouteCollector $routeCollector): void {
$routes = include(BASE_PATH . "/routes/web.php");
foreach ($routes as $route) {
$routeCollector -> addRoute(...$route);
}
};
$dispatcher = FastRoute::recommendedSettings($routeDefinition, BASE_PATH . "/routes.cache") -> disableCache() -> dispatcher();
$routeInfo = $dispatcher -> dispatch(
$request -> getMethod(),
$request -> getPathInfo()
);
// Handle the request...
One more thing, can you also explain to me the $routeDefinition? It's a variable that equals a static function (which for me is inside a method), that's new to me. And also how does the caching work?
If it's too obvious then close this issue already 😴