Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Abstract Factories handling is inconsistent with normal Factories #5289

Closed
weierophinney opened this issue Oct 17, 2013 · 1 comment
Closed
Milestone

Comments

@weierophinney
Copy link
Member

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
@stefanotorresi
Copy link
Contributor

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
…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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants