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

RequestResponseArgs guess data types of args #2687

Closed
bednic opened this issue May 10, 2019 · 7 comments
Closed

RequestResponseArgs guess data types of args #2687

bednic opened this issue May 10, 2019 · 7 comments

Comments

@bednic
Copy link
Contributor

bednic commented May 10, 2019

I have an idea about RequestResponseArgs handle strategy in Slim 4, it should be nice, if this strategy cast data types of args right. Like if I have method($request, $response, int $id, string $value), then this strategy cast first arg as int, second arg as string, if no data type is provided, then cast is as string.

@bednic bednic changed the title RequestResponseArgs guess data types RequestResponseArgs guess data types of args May 10, 2019
@l0gicgate
Copy link
Member

l0gicgate commented May 10, 2019

@bednic you can create your own strategy and set it on the RouteCollector to be the default strategy for when you add routes.

$app = AppFactory::create();

$strategy = new MyCustomRouteInvocationStrategy();

// Do it for all routes
$routeCollector = $app->getRouteCollector();
$routeCollector->setDefaultRouteInvocationStrategy($strategy);

// Do it for one route only
$app->get('/', function (...) {...})->setInvocationStrategy($strategy);

@bednic
Copy link
Contributor Author

bednic commented May 10, 2019

Yea I know, I can. It was just idea to enchant your strategy to make it more sexy. It doesn't mean it's bug or something. I'm just curious if you are even interested in this improvement and then if you approve this idea I can make some MR later.

@l0gicgate
Copy link
Member

I'm not opposed to an improvement as long as it doesn't break the existing functionality. I suppose you'd have to do the parameter detection through reflection and there's going to be a lot of edge cases.. Definitely open to a PR if you want!

@jhuet
Copy link

jhuet commented May 20, 2019

Just to give my 2 cents, PHP-DI bridge does this thanks to his Invoker : https://github.com/PHP-DI/Slim-Bridge/blob/master/src/ControllerInvoker.php

@bednic
Copy link
Contributor Author

bednic commented May 20, 2019

It's true, I used to use it in previous version of Slim. I didn't expect it will work with Slim 4, don't know why 🤨. But there is one tricky case with optional parameters. But I suppose it fits my requirement. I will try setup my skeleton with that.

@l0gicgate
Copy link
Member

Again, feel free to PR this so we can add it to the library of route invocation strategies. I have no problems with it, it's never going to be the default strategy though.

@l0gicgate
Copy link
Member

l0gicgate commented Aug 6, 2019

Slim-Bridge is adding support for Slim 4. I'm closing this as resolved.

See PHP-DI/Slim-Bridge#47

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

No branches or pull requests

3 participants