Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active route pattern #225

Closed
Jackson88 opened this issue Dec 14, 2020 · 7 comments · Fixed by #269
Closed

Active route pattern #225

Jackson88 opened this issue Dec 14, 2020 · 7 comments · Fixed by #269
Assignees
Milestone

Comments

@Jackson88
Copy link

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.

@burzum
Copy link
Contributor

burzum commented Dec 19, 2020

I'm not sure what you mean? You want to be able to get the matched pattern in the result?

@Jackson88
Copy link
Author

Exactly, be able to identify used route "rule", for general purposes like statistic/analytics

@burzum
Copy link
Contributor

burzum commented Dec 28, 2020

@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

@burzum
Copy link
Contributor

burzum commented Apr 10, 2021

@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.

@kktsvetkov
Copy link

@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.

@kktsvetkov
Copy link

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.

@WilliamStam
Copy link

"extra parameters" would be really cool. that would make life SOOO much easier with auth middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants