-
Notifications
You must be signed in to change notification settings - Fork 87
[Bugfix] Check if container contains method before calling it #143
[Bugfix] Check if container contains method before calling it #143
Conversation
…iceManager` instances without implementing `ServiceLocatorAwareInterface` or providing `getServiceLocator` method
$container->getServiceLocator()
on `Serv…
@asgrim Could you have a look at this or probably ping someone who might be responsible? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve the issue of the interface and additionally please add a test that provides the existing failure condition.
@@ -191,7 +192,9 @@ public function __construct($configInstanceOrParentLocator = null, array $v3conf | |||
public function injectFactory($instance, ContainerInterface $container) | |||
{ | |||
// Need to retrieve the parent container | |||
$container = $container->getServiceLocator() ?: $container; | |||
if ($container instanceof ServiceLocatorAwareInterface || method_exists($container, 'getServiceLocator')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, in this case, I would not suggest looking to see if the method exists but rather only checking against the ServiceLocatorAwareInterface as that is the interface that defines this definition rather than allowing duck typing of something that may not be following the interface. The interface gives us a contractual obligation.
This change is incorrect! That particular class should only ever be in play if zend-servicemanager v2 is in use, in which case we can depend on that method being present. I think you've found an incorrect solution to the problem you've identified. |
@weierophinney Exactly. And since zend-servicemanager v2
Using the following versions:
|
I've reverted my changes and added a failing unit-test instead. |
problem is it expects abstract plugin manager |
So is the I actually want to use the FormAnnotationBuilderFactory. So I could ensure that |
@boesing — The following:
is irrelevant. The FormElementManager is an Under zend-servicemanager v2, when a service is being pulled from a plugin manager, the Under zend-servicemanager v3, the I've looked at the test case you wrote, and noted that it is not written correctly for zend-servicemanager v2; the second argument to As such, this points to the core issue: the $formElementManager->injectFactory($container, $annotationBuilder); This is incorrect in two ways:
It should more correctly read: method_exists($container, 'configure'))
? $formElementManager->injectFactory($container, $annotationBuilder) // zend-servicemanager v3
: $formElementManager->injectFactory($annotationBuilder, $formElementManager); // zend-servicemanager v2 I'll submit a PR against the 2.7 branch shortly to do this. |
@boesing I've just seen your zendframework/zend-mvc#223, and that does it correctly as well, so that'll be the one I merge. |
I guess you meant zendframework/zend-mvc#223. |
Indeed. Edited my comment to reflect that. 😄 |
Do not blindly call
getServiceLocator
onContainerInterface
which must not implement that method.