bramus / bramus/router

how to get which route is run?

Open
#81 3 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
PHP
Stars
1.1k
Forks
236
PR merge metrics
No merged PRs in 30d

Description

Let's say I have twenty routes in my project, and I want to log every request with the route. Currently, I do

``` php
$bramus->all("/user/{id}", function () {
logRequest("/user/{id]")
}
```

Of course this is grossly oversimplified. I would like to not have to send the route as a parameter and get it from `bramus/router`. I added `$this->runRoutes[] = $route["pattern"];` to the `handle()` function and this is enough at the moment but I would like to know if there is already a way to get a list of matching (and running) routes from `bramus/router`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the router's handle() function, where the issue currently records route patterns in runRoutes[]. Trace how matching routes are selected and run, then determine how the active route can be exposed without passing it to each handler. Done means callers can retrieve the matching and running route for request logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.