bramus / bramus/router

Feature Request: Add ->use method

Open
#223 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.1k
Forks
236
PR merge metrics
No merged PRs in 30d

Description

Add a new method like express.use() to pass down frequently used variables like database or other class instances, because when working with many routes, writing many variables with the use statement becomes a bit too much.
Example:
```
$database = new Database();
$router->use($database);

$router->get('/user/{id}', function ($id) {
$user = $database->query("SELECT * FROM users WHERE id = ?", [$id]);
if ($user) {
echo json_encode($user);
} else {
echo "User not found";
}
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the router’s existing route registration and callback invocation code to determine where shared instances could be carried. Compare the requested express.use()-style behavior with the example, then define how routes receive the database and how completion will be verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.