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

Commit 35aa5ca

Browse files
committed
Remove deprecated ServiceLocatorAware initializers
- Bumps zend-servicemanager to only v3 versions. - Removes ServiceLocatorAware initializers from both ServiceManagerConfig and ControllerManager
1 parent 0208026 commit 35aa5ca

File tree

3 files changed

+1
-120
lines changed

3 files changed

+1
-120
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"zendframework/zend-http": "^2.5.4",
1919
"zendframework/zend-modulemanager": "^2.7.1",
2020
"zendframework/zend-router": "^3.0",
21-
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
21+
"zendframework/zend-servicemanager": "^3.0.3",
2222
"zendframework/zend-stdlib": "^2.7.5 || ^3.0",
2323
"zendframework/zend-view": "^2.6.3",
2424
"container-interop/container-interop": "^1.1"

src/Controller/ControllerManager.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public function __construct($configOrContainerInstance, array $v3config = [])
5454
$this->addInitializer([$this, 'injectEventManager']);
5555
$this->addInitializer([$this, 'injectPluginManager']);
5656
parent::__construct($configOrContainerInstance, $v3config);
57-
58-
// Added after parent construction, as v2 abstract plugin managers add
59-
// one during construction.
60-
$this->addInitializer([$this, 'injectServiceLocator']);
6157
}
6258

6359
/**
@@ -165,52 +161,4 @@ public function injectPluginManager($first, $second)
165161

166162
$controller->setPluginManager($container->get('ControllerPluginManager'));
167163
}
168-
169-
/**
170-
* Initializer: inject service locator
171-
*
172-
* @param ContainerInterface|DispatchableInterface $first Container when
173-
* using zend-servicemanager v3; controller under v2.
174-
* @param DispatchableInterface|ContainerInterface $second Controller when
175-
* using zend-servicemanager v3; container under v2.
176-
*/
177-
public function injectServiceLocator($first, $second)
178-
{
179-
if ($first instanceof ContainerInterface) {
180-
$container = $first;
181-
$controller = $second;
182-
} else {
183-
$container = $second;
184-
$controller = $first;
185-
}
186-
187-
// For v2, we need to pull the parent service locator
188-
if (! method_exists($container, 'configure')) {
189-
$container = $container->getServiceLocator() ?: $container;
190-
}
191-
192-
// Inject AbstractController extensions that are not ServiceLocatorAware
193-
// with the service manager, but do not emit a deprecation notice. We'll
194-
// emit it from AbstractController::getServiceLocator() instead.
195-
if (! $controller instanceof ServiceLocatorAwareInterface
196-
&& $controller instanceof AbstractController
197-
&& method_exists($controller, 'setServiceLocator')
198-
) {
199-
// Do not emit deprecation notice in this case
200-
$controller->setServiceLocator($container);
201-
}
202-
203-
// If a controller implements ServiceLocatorAwareInterface explicitly, we
204-
// inject, but emit a deprecation notice. Since AbstractController no longer
205-
// explicitly does this, this will only affect userland controllers.
206-
if ($controller instanceof ServiceLocatorAwareInterface) {
207-
trigger_error(sprintf(
208-
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
209-
. 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
210-
. 'the implementation, and start injecting your dependencies via factory instead.',
211-
get_class($controller)
212-
), E_USER_DEPRECATED);
213-
$controller->setServiceLocator($container);
214-
}
215-
}
216164
}

src/Service/ServiceManagerConfig.php

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -109,73 +109,6 @@ public function __construct(array $config = [])
109109

110110
$instance->setEventManager($container->get('EventManager'));
111111
},
112-
'ServiceManagerAwareInitializer' => function ($first, $second) {
113-
if ($first instanceof ContainerInterface) {
114-
// zend-servicemanager v3
115-
$container = $first;
116-
$instance = $second;
117-
} else {
118-
// zend-servicemanager v2
119-
$container = $second;
120-
$instance = $first;
121-
}
122-
123-
if ($container instanceof ServiceManager && $instance instanceof ServiceManagerAwareInterface) {
124-
trigger_error(sprintf(
125-
'ServiceManagerAwareInterface is deprecated and will be removed in version 3.0, along '
126-
. 'with the ServiceManagerAwareInitializer. Please update your class %s to remove '
127-
. 'the implementation, and start injecting your dependencies via factory instead.',
128-
get_class($instance)
129-
), E_USER_DEPRECATED);
130-
$instance->setServiceManager($container);
131-
}
132-
},
133-
'ServiceLocatorAwareInitializer' => function ($first, $second) {
134-
if ($first instanceof AbstractPluginManager) {
135-
// Edge case under zend-servicemanager v2
136-
$container = $second;
137-
$instance = $first;
138-
} elseif ($first instanceof ContainerInterface) {
139-
// zend-servicemanager v3
140-
$container = $first;
141-
$instance = $second;
142-
} else {
143-
// zend-servicemanager v2
144-
$container = $second;
145-
$instance = $first;
146-
}
147-
148-
// For service locator aware classes, inject the service
149-
// locator, but emit a deprecation notice. Skip plugin manager
150-
// implementations; they're dealt with later.
151-
if ($instance instanceof ServiceLocatorAwareInterface
152-
&& ! $instance instanceof AbstractPluginManager
153-
) {
154-
trigger_error(sprintf(
155-
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
156-
. 'with the ServiceLocatorAwareInitializer. Please update your class %s to remove '
157-
. 'the implementation, and start injecting your dependencies via factory instead.',
158-
get_class($instance)
159-
), E_USER_DEPRECATED);
160-
$instance->setServiceLocator($container);
161-
}
162-
163-
// For service locator aware plugin managers that do not have
164-
// the service locator already injected, inject it, but emit a
165-
// deprecation notice.
166-
if ($instance instanceof ServiceLocatorAwareInterface
167-
&& $instance instanceof AbstractPluginManager
168-
&& ! $instance->getServiceLocator()
169-
) {
170-
trigger_error(sprintf(
171-
'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
172-
. 'with the ServiceLocatorAwareInitializer. Please update your %s plugin manager factory '
173-
. 'to inject the parent service locator via the constructor.',
174-
get_class($instance)
175-
), E_USER_DEPRECATED);
176-
$instance->setServiceLocator($container);
177-
}
178-
},
179112
]);
180113

181114
// In zend-servicemanager v2, incoming configuration is not merged

0 commit comments

Comments
 (0)