zendframework / zend-servicemanager

ServiceManager component from Zend Framework
BSD 3-Clause "New" or "Revised" License
188 stars 89 forks source link

Lazy services with factories #118

Closed metanav closed 8 years ago

metanav commented 8 years ago

I am using a lazy service but I guess proxy is not being generated correctly. Or, I am missing some basic things. I have created a gist: https://gist.github.com/metanav/0017ee8b3171e079be2fc165ccf69ac9

Ocramius commented 8 years ago

What is the outcome? Btw, the class map seems incorrect: should map from service name to expected instance type, not to factories. On May 12, 2016 18:03, "Naveen" notifications@github.com wrote:

I am using a lazy service but I guess proxy is not being generated correctly. Or, I am missing some basic things. I have created a gist: https://gist.github.com/metanav/0017ee8b3171e079be2fc165ccf69ac9

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/zendframework/zend-servicemanager/issues/118

metanav commented 8 years ago

it throws the error: Fatal error: Call to undefined method ProxyManagerGeneratedProxyPM\SocialAuth\Adapter\Factory\HybridAuthAdapterFactory\Generatedc168519a10309fef32fc623cefbfddd3::authenticate()

I have modified the class_map (see the updated gist) and seems working. Just wondering how the proxy manager calls the factory and inject dependencies to the instance?

metanav commented 8 years ago

Also, how to know whether the generated proxy can call the real object? Suppose for some reason real object creation gets failed due to some exception and it is set as null in proxy. How can be checked if it is null?

Ocramius commented 8 years ago

I have modified the class_map (see the updated gist) and seems working.

So the issue is fixed?

Just wondering how the proxy manager calls the factory and inject dependencies to the instance?

That is a bit more advanced: you will need to read the ProxyManager documentation. You can also read further in https://github.com/Ocramius/ProxyManager/tree/2.0.1/docs

Also, how to know whether the generated proxy can call the real object? Suppose for some reason real object creation gets failed due to some exception and it is set as null in proxy. How can be checked if it is null?

This is a very good point, and I don't think that ProxyManager provides any utility to check that at the moment. Could you open an issue on ProxyManager with a possible failure scenario (once you caught up on the docs for it)?

Ocramius commented 8 years ago

Closing here, since the question turned out to be a misconfiguration issue.