17
17
use Zend \EventManager \SharedEventManagerInterface ;
18
18
use Zend \ModuleManager \Listener \ServiceListener ;
19
19
use Zend \ModuleManager \ModuleManager ;
20
+ use Zend \ServiceManager \AbstractPluginManager ;
20
21
use Zend \ServiceManager \Config ;
21
22
use Zend \ServiceManager \ServiceLocatorAwareInterface ;
22
23
use Zend \ServiceManager \ServiceManager ;
@@ -132,7 +133,12 @@ public function __construct(array $config = [])
132
133
$ instance = $ first ;
133
134
}
134
135
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
+ ) {
136
142
trigger_error (sprintf (
137
143
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
138
144
. 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
@@ -142,13 +148,17 @@ public function __construct(array $config = [])
142
148
$ instance ->setServiceLocator ($ container );
143
149
}
144
150
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 ()
147
157
) {
148
158
trigger_error (sprintf (
149
159
'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 . ' ,
152
162
get_class ($ instance )
153
163
), E_USER_DEPRECATED );
154
164
$ instance ->setServiceLocator ($ container );
0 commit comments