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

[Bugfix] Check if container contains method before calling it #143

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/FormElementManager/FormElementManagerV2Polyfill.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Zend\Form\FormFactoryAwareInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\ConfigInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\Stdlib\InitializableInterface;

/**
Expand Down Expand Up @@ -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')) {
Copy link
Contributor

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.

$container = $container->getServiceLocator() ?: $container;
}

if (! $instance instanceof FormFactoryAwareInterface) {
return;
Expand Down