1717use Zend \EventManager \SharedEventManagerInterface ;
1818use Zend \ModuleManager \Listener \ServiceListener ;
1919use Zend \ModuleManager \ModuleManager ;
20+ use Zend \ServiceManager \AbstractPluginManager ;
2021use Zend \ServiceManager \Config ;
2122use Zend \ServiceManager \ServiceLocatorAwareInterface ;
2223use Zend \ServiceManager \ServiceManager ;
@@ -132,7 +133,12 @@ public function __construct(array $config = [])
132133 $ instance = $ first ;
133134 }
134135
135- if ($ instance instanceof ServiceLocatorAwareInterface) {
136+ // For service locator aware classes, inject the service
137+ // locator, but emit a deprecation notice. Skip plugin manager
138+ // implementations; they're dealt with later.
139+ if ($ instance instanceof ServiceLocatorAwareInterface
140+ && ! $ instance instanceof AbstractPluginManager
141+ ) {
136142 trigger_error (sprintf (
137143 'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
138144 . 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
@@ -142,13 +148,17 @@ public function __construct(array $config = [])
142148 $ instance ->setServiceLocator ($ container );
143149 }
144150
145- if (! $ instance instanceof ServiceLocatorAwareInterface
146- && method_exists ($ instance , 'setServiceLocator ' )
151+ // For service locator aware plugin managers that do not have
152+ // the service locator already injected, inject it, but emit a
153+ // deprecation notice.
154+ if ($ instance instanceof ServiceLocatorAwareInterface
155+ && $ instance instanceof AbstractPluginManager
156+ && ! $ instance ->getServiceLocator ()
147157 ) {
148158 trigger_error (sprintf (
149159 '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 . ' ,
160+ . 'with the ServiceLocatorAwareInitializer. Please update your %s plugin manager factory '
161+ . 'to inject the parent service locator via the constructor . ' ,
152162 get_class ($ instance )
153163 ), E_USER_DEPRECATED );
154164 $ instance ->setServiceLocator ($ container );
0 commit comments