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

Commit 5cb953e

Browse files
committed
Duck-type ServiceLocatorAwareInterface
Since zend-servicemanager v3 does not define `ServiceLocatorAwareInterface`, then we cannot extend it and still support that release series. As such, `AbstractController` no longer explicitly implements it, but does so implicitly by defining the methods. The initializers in both `ServiceManagerConfig` and `ControllerManager` were updated to *also* look for the combination: - interface `ServiceLocatorAwareInterface` does not exist AND - method `setServiceLocator()` is present If that combination is present, the same behavior is retained, including the deprecation notices.
1 parent be9c248 commit 5cb953e

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/Controller/AbstractController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Zend\Http\Request as HttpRequest;
1818
use Zend\Mvc\InjectApplicationEventInterface;
1919
use Zend\Mvc\MvcEvent;
20-
use Zend\ServiceManager\ServiceLocatorAwareInterface;
2120
use Zend\ServiceManager\ServiceLocatorInterface;
2221
use Zend\ServiceManager\ServiceManager;
2322
use Zend\Stdlib\DispatchableInterface as Dispatchable;
@@ -47,8 +46,7 @@
4746
abstract class AbstractController implements
4847
Dispatchable,
4948
EventManagerAwareInterface,
50-
InjectApplicationEventInterface,
51-
ServiceLocatorAwareInterface
49+
InjectApplicationEventInterface
5250
{
5351
/**
5452
* @var PluginManager

src/Controller/ControllerManager.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ public function injectServiceLocator($first, $second)
217217
$container = $container->getServiceLocator() ?: $container;
218218
}
219219

220+
if (! interface_exists(ServiceLocatorAwareInterface::class)
221+
&& method_exists($controller, 'setServiceLocator')
222+
) {
223+
trigger_error(sprintf(
224+
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
225+
. 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
226+
. 'the implementation, and start injecting your dependencies via factory instead.',
227+
get_class($controller)
228+
), E_USER_DEPRECATED);
229+
$controller->setServiceLocator($container);
230+
}
231+
220232
if ($controller instanceof ServiceLocatorAwareInterface) {
221233
trigger_error(sprintf(
222234
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '

src/Service/ServiceManagerConfig.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ public function __construct(array $config = [])
141141
), E_USER_DEPRECATED);
142142
$instance->setServiceLocator($container);
143143
}
144+
145+
if (! interface_exists(ServiceLocatorAwareInterface::class)
146+
&& method_exists($instance, 'setServiceLocator')
147+
) {
148+
trigger_error(sprintf(
149+
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
150+
. 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
151+
. 'the implementation, and start injecting your dependencies via factory instead.',
152+
get_class($instance)
153+
), E_USER_DEPRECATED);
154+
$instance->setServiceLocator($container);
155+
}
144156
},
145157
]);
146158

0 commit comments

Comments
 (0)