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

Support ServiceControllerServiceProvider #7

Closed
jdreesen opened this issue Oct 13, 2015 · 6 comments
Closed

Support ServiceControllerServiceProvider #7

jdreesen opened this issue Oct 13, 2015 · 6 comments

Comments

@jdreesen
Copy link
Collaborator

The Silex bridge cannot be used together with Silex\Provider\ServiceControllerServiceProvider because it always returns an empty array in ControllerResolverInterface::getArguments().

The ServiceControllerServiceProvider decorates the ControllerResolver of the app, so that the ControllerResolver::getController() method of this bridge gets only called if the controller is no Silex service. If it is, only ControllerResolver::getArguments() of this bridge gets called, which always returns an empty array and thus the controller action will be called without arguments, resulting in an error.

It seems that we'd need an instance of Invoker\ParameterResolver\ParameterResolver to resolve the parameters of the controller but I don't know how to get it from the container because it's private.

@mnapoli
Copy link
Member

mnapoli commented Oct 14, 2015

Hi! Right I see what you mean thanks for the details. I'm curious as to why you would use the ServiceControllerServiceProvider since this bridge already does the "controller as a service" thing?

Anyway this PR might help: PHP-DI/Invoker#2 With this, we could use CallableResolver in ControllerResolver::getController() and for ControllerResolver::getArguments() we could create a ParameterResolver manually. After all, PHP-DI's invoker is simple: https://github.com/PHP-DI/PHP-DI/blob/master/src/DI/Container.php#L321-L329

            $parameterResolver = new ResolverChain([
                new AssociativeArrayResolver,
                new TypeHintContainerResolver($this->wrapperContainer),
            ]);

That would be an even simpler invoker (so faster, more predictable, …) and we could use it directly.

@jdreesen
Copy link
Collaborator Author

I'm curious as to why you would use the ServiceControllerServiceProvider since this bridge already does the "controller as a service" thing?

You are right and it's not me using the ServiceControllerServiceProvider (at least not directly) but the WebProfilerServiceProvider I tried to include.

Thanks for your suggestions :)
I'll play around with them a bit in the next days (if I find the time) and send a PR if I found a solution.

@mnapoli mnapoli changed the title Error in conjunction with Silex\Provider\ServiceControllerServiceProvider Support ServiceControllerServiceProvider Oct 18, 2015
@jdreesen
Copy link
Collaborator Author

I just pushed a first version that implements ControllerResolver::getArguments() to my fork: jdreesen@0ee3381

However, this does not work with controllers that need to be resolved from the container. We would need PHP-DI/Invoker#2 for this, so is there anything preventing it to be merged?

@mnapoli
Copy link
Member

mnapoli commented Oct 22, 2015

👍 I'll rebase PHP-DI/Invoker#2 and try to merge it

@mnapoli
Copy link
Member

mnapoli commented Oct 22, 2015

@jdreesen rebasing was too painful ;) I created a new PR and merged it: https://github.com/PHP-DI/Invoker/releases/tag/1.2.0

@jdreesen
Copy link
Collaborator Author

Very nice, thx! :)

I don't have free time until next week but then I'll update my commit and send a PR.

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

2 participants