add route group
$app->addGroup('/users', [
// middleware1,
// middleware2
], function ($app) {
$app->get('/{name}', function ($request) {
return \React\Http\Message\Response::plaintext(
"Hello " . $request->getAttribute('name') . "!\n"
);
});
$app->addGroup('/{name}/posts', [
// middleware1,
// middleware2
], function ($app) {
$app->get('/{post}', function ($request) {
return \React\Http\Message\Response::plaintext(
"Hello User {$request->getAttribute('name')} Posts " . $request->getAttribute('post') . "!\n"
);
});
});
});
$app->addGroup('/posts', [
// middleware1,
// middleware2
], function ($app) {
$app->get('/{post}', function ($request) {
return \React\Http\Message\Response::plaintext(
"Hello Posts " . $request->getAttribute('post') . "!\n"
);
});
});
In the past few days of use, it has been very useful to control between different grouping APIs. I have compiled some tests, covering all the cases I can think of.
I think it's done!
Feel free to close the PR if you don't find it useful.
@wpjscc Thanks for opening this pull request and adding tests to confirm your changes 💪
As you may already know, we're currently working on a first version for Framework X which should go live tomorrow, see https://twitter.com/x_framework/status/1762499173830778907.
In preparation for this release, we've been brainstorming a ton of new features, including the possibility of supporting route groups. This is definitely a topic we'd like to see being part of Framework X!
While talking about route groups, we also came up with some plans for the current RouteHandler and the whole handler structure in general. Nothing set in stone yet, but the currently internal RouteHandler will probably be public at some point and renamed to Router. With that in mind, I'm not sure if we can start with an implementation on route groups today that may be completely changed in the future and thus force foreseeable BC breaks.
I really appreciate the time and thoughts you put into this (I really do!) and I invite you to keep using your implementation for the time being. However, I'm not sure if merging this is the right decision at the moment with the other plans we have in place.
I'll close this for ticket for now, but we'll definitely revisit this in an upcoming release! 👍️