zendframework / zend-servicemanager

ServiceManager component from Zend Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG or INTENTION: ServiceManager::has() does not consider delegators and lazy services!

fhein opened this issue · comments

I consider this a bug. But because it's so obvious, it may be intention.
I could fix that. Please advice.

Factories only work, if they are invokable. This is checked when requested also. Isn't that similar to delegators?

It is not checked that a factory is able to create a service currently. The answer (true) you might get from has() does not grant that you can actually successfully get() that item. Does that behaviour conform to PSR-11?

It is quite difficult for me to understand, what the difference is. A factory key relies on a proper factory setup. A delegator key relies on a proper delegator setup (which again relies on properly defined factories). They both have to assume much , because nothing gets checked at configuration time.

Two possible solutions: Accept the current state and check delegates also (in has()). This would be for consistency (with factories) but would not comply to the standard. Or: Check at configuration time, whether the supplied factories and delegators are valid enough specified to grant that people can get() the ServiceManager announces to have (has()). This would be compliant to defined standards.

Alternative: Discard has(). But this would break with the standard.

IIRC, parameter checks once where part of ServiceManager.

If the plans for ServiceManager do not include compliance to PSR-11, there seems to be no need to change container inheritance to PSR-11 (which would be a bc break).

Please advice.

Ok. So sm doesn't predict to have a delegator?

No, that's really just decoration happening during service creation.

F***, of course you are right. That was a stupid one. RTFM. Sorry ...