-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: can add route handler as callable #5713
Conversation
Please include additions in the user guide |
9c11934
to
77a0302
Compare
What about? //[Home::class, 'index', '$1/$2']
[$class, $method, $params] = $to;
is_callable([$class, $method], true, $callableName)
//... |
Yes, you are right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs writeup in the docs.
In theory. Can we drop |
I will write the docs later. |
77a0302
to
e7230dc
Compare
Added User Guide. |
e7230dc
to
115fc77
Compare
@kenjis can you reply to the comment above? $routes->get('product/(:num)/(:num)', [Hello::class, 'index']); Here we already have two arguments $routes->get('product/(:num)/(:num)', fn ($param1, $param2) => 'do something'); i.e. we don't specify |
This looks like a great addition. I would be in favor of removing the $1/$2 params as being specifically needed. While I've had times in the past where I needed to reorder or leave out some parameters, it's never been a big enough deal that it couldn't be worked around, and would clean this up a bit. Maybe make it optional? If it's not provided it defaults to the order given? |
To skip the parameter, the developer can use non-capturing grouping. |
115fc77
to
b2fb66d
Compare
@iRedds @lonnieezell how about this? |
It will not work correctly with a non-capturing group. It seems to me that if you use your approach, then you need to trim the slash in } elseif (strpos($val, '$') === false && count($matches) > 1) {
array_shift($matches);
$val.= '/' . implode('/', $matches);
}
$this->setRequest(explode('/', $val)); This solution will also allow parameters to be applied to more than just the $to array. |
I think regex is originally complex, and we do not need to support all the pattern.
Or I don't mind to change the implementation if there is simple better one. But if |
E.g.: $routes->add('home', [Hello::class, 'index']); $routes->add('product/(:num)/(:num)', [[Hello::class, 'index'], '$1/$2']);
b2fb66d
to
464ed03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks!
@paulbalandan The commit you approved failed tests. |
Description
E.g.:
Checklist: