-
Notifications
You must be signed in to change notification settings - Fork 10
zf-rpc fails for controller classes with same name in callable #18
Comments
What does the route definition look like? |
In the test I didn't define a route, that was not necessary to reproduce the problem.
|
How is it not necessary to reproduce the problem? How exactly are you fetching the controller, if not when routing? Honestly, I'm having trouble understanding the full context of the problem. You're reporting something that looks like a cyclical dependency lookup, but I'm not sure how the lookup is being triggered — which is why I asked about routing. And that routing example looks problematic: the name doesn't match what you wrote above ( UpdateIn looking at this more closely, it looks like the |
Maybe I was not clear in my question, but I provided a unit test that reproduces the problem in an test case. What I meant was that setting a route was not necessary to reproduce the issue in this unit test. Thanks for looking into this issue. |
@Wilt I had indeed missed the test case! (it's in I can verify that the test never completes, which mimics the behavior you reported. Curious to see if I can figure out why now! |
I figured out what's going on, but I'm not sure how to fix it. Essentially, what happens is this: the abstract factory splits the The problem is this: when the class name is passed to the I'm totally stymied at how we might correct this. The only thing I can think of is a userland workaround: use a different name for the zf-rpc entry and the callable it would resolve to. This could work in one of two ways:
I might be able to do a circular-dependency check, but the ideas I have so far have some definite short-comings, particularly when working in async application runners, so I need to test a bit more. |
As reported in zfcampus#18, a circular dependency lookup can occur when specifying a static method of a class as a `callable` for an RPC service that matches the class name for the RPC service. As an example: ```php return [ 'zf-rpc' => [ SomeController::class => [ 'callable' => SomeController::class . '::bar', ], ], ]; ``` In the above case, the `RpcControllerFactory` would be invoked for `SomeController::class`, find the `callable` entry of `{NS}\SomeController::bar`, split this into the class and method, and then attempt to fetch `SomeController::class` again, ad infinitum. This patch adds a private property, `$lastRequestedControllerService`, which is set to the service being pulled whenever we attempt to marshal a service from the controller manager. If a subsequent invocation finds that the service requested matches that property value, then we do not attempt to pull from the controller manager again, but move on to the parent container (if we have one), or directly instantiating the class. (The `$lastRequestedControllerService` is reset otherwise.) Fixes zfcampus#18
As reported in zfcampus#18, a circular dependency lookup can occur when specifying a static method of a class as a `callable` for an RPC service that matches the class name for the RPC service. As an example: ```php return [ 'zf-rpc' => [ SomeController::class => [ 'callable' => SomeController::class . '::bar', ], ], ]; ``` In the above case, the `RpcControllerFactory` would be invoked for `SomeController::class`, find the `callable` entry of `{NS}\SomeController::bar`, split this into the class and method, and then attempt to fetch `SomeController::class` again, ad infinitum. This patch adds a private property, `$lastRequestedControllerService`, which is set to the service being pulled whenever we attempt to marshal a service from the controller manager. If a subsequent invocation finds that the service requested matches that property value, then we do not attempt to pull from the controller manager again, but move on to the parent container (if we have one), or directly instantiating the class. (The `$lastRequestedControllerService` is reset otherwise.) Fixes zfcampus#18
I finally managed to find some time to continue working with this and now I noticed that I get a double wrapped callable as a controller from the
The callable inside the It seems like the fix solved the circular dependency lookup but wraps the result 2 times. Repository: Added to test: |
@Wilt Can you send a PR with the test case, please? |
Done, can be found here: #20 |
I am trying to register classes according to the example in the documentation, where the (controller) class name used as the key in the
zf-rpc
configuration and the class name for the callable are corresponding (in the example belowApplication\Controller\LoginController
).The application ends in a infinite loop :
And this process repeats...
I will provide a test case that shows this problem in a forked repository here:
https://github.com/Wilt/zf-rpc/tree/issue18
Expected results
It should simply create the
RpcController
instance.Actual results
Infinite loop.
Solution
I could provide a solution in a pull-request, but I need some guidance in where I preferably should change the code base for this.
The text was updated successfully, but these errors were encountered: