FastRoute
FastRoute copied to clipboard
Active route pattern
Hello, kinda question: is it possible to define the active route pattern itself, for example:
$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/user/{id:\d+}', 'get_user_handler');
});
....
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
$activePattern = $routeInfo[3]; // '/user/{id:\d+}'
Regards.
I'm not sure what you mean? You want to be able to get the matched pattern in the result?
Exactly, be able to identify used route "rule", for general purposes like statistic/analytics
@Jackson88 the router builds a regex-map internally I don't think the current version allows you to identify the used route declaration but I'm working towards being able to do so in #233
@Jackson88 you can just use Google Analytics or the PSR request object and it's URL itself to generate statistics. I don't see how a route itself gives you good statistics.
@Jackson88 can you use the handler instead of the route to track the states? In other words, instead of tracking how many times the route was matched, you are going to track how many times the handler was returned as result. In most cases, if there are no duplicate routes for the same handler, it should do the job.
In Symfony Routing there is this feature called "Extra Parameters", where when you declare a route you not only assign a handler to it, but you can also attach some extra parameters that will be included in the results if the route is matched. I think under the hood this is what Symfony Routing is using to remember the route names as well.
I think such a feature here will help both with the named routes, as well as with any other baggage that you want to pass along with a route that has been matched.
"extra parameters" would be really cool. that would make life SOOO much easier with auth middleware.