Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Abstract Factories handling is inconsistent with normal Factories #5289

Closed
weierophinney opened this Issue Oct 17, 2013 · 1 comment

Comments

Projects
None yet
3 participants
Owner

weierophinney commented Oct 17, 2013

See this line: https://github.com/zendframework/zf2/blob/master/library/Zend/ServiceManager/ServiceManager.php#L1040-L1042

Essentially, if your abstract factory returns anything other than an object, the SM moves on to the next abstract factory. This means that if a later AF returns a value, that will be used, or, if whatever the last AF returns, regardless of type, will be returned.

As an example, if we register 3 abstract factories, and each return arrays, the last AF's value will be returned, even though the first clearly returned a value. This is inconsistent with factories, where any non-null value may be returned as a service, which is in turn inconsistent with how setService() works (only arrays and objects are valid).

At the very least, createFromAbstractFactory should return immediately if a non-null value is returned by a give abstract factory. Better yet, we should also loosen up how setService() works, to allow setting the same type range as factories do.

@ghost ghost assigned ralphschindler Oct 17, 2013

Contributor

stefanotorresi commented Oct 18, 2013

FWIW I was about to make a PR for this. Shall I?

edit: actually I'll just submit the PR and let you decide what to do with it :p

weierophinney added a commit that referenced this issue Oct 23, 2013

weierophinney added a commit to zendframework/zend-servicemanager that referenced this issue May 15, 2015

Merge pull request zendframework/zendframework#5293 from stefanotorre…
…si/hotfix/5289


Fix zendframework/zendframework#5289 (abstract factories return type)

Conflicts:
	tests/ZendTest/ServiceManager/ServiceManagerTest.php

weierophinney added a commit to zendframework/zend-servicemanager that referenced this issue May 15, 2015

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