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

Commit 5d9cdd4

Browse files
authored
Merge pull request #211 from snapshotpl/remove-sm-v3
Remove support code for servicemanager and eventmanager v2
2 parents b15a5b7 + c9fc99f commit 5d9cdd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+118
-989
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ All notable changes to this project will be documented in this file, in reverse
1414

1515
### Removed
1616

17-
- Nothing.
17+
- [#211](https://github.com/zendframework/zend-mvc/pull/211) Removed unused
18+
zend-servicemanager v2 and zend-eventmanager v2 compatibility code since
19+
zend-mvc requires v3 of those components.
1820

1921
### Fixed
2022

src/Controller/ControllerManager.php

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Interop\Container\ContainerInterface;
1313
use Zend\EventManager\EventManagerAwareInterface;
1414
use Zend\EventManager\SharedEventManagerInterface;
15-
use Zend\Mvc\Exception;
1615
use Zend\ServiceManager\AbstractPluginManager;
1716
use Zend\ServiceManager\ConfigInterface;
1817
use Zend\ServiceManager\Exception\InvalidServiceException;
@@ -46,17 +45,17 @@ class ControllerManager extends AbstractPluginManager
4645
* event manager and plugin manager.
4746
*
4847
* @param ConfigInterface|ContainerInterface $container
49-
* @param array $v3config
48+
* @param array $config
5049
*/
51-
public function __construct($configOrContainerInstance, array $v3config = [])
50+
public function __construct($configOrContainerInstance, array $config = [])
5251
{
5352
$this->addInitializer([$this, 'injectEventManager']);
5453
$this->addInitializer([$this, 'injectPluginManager']);
55-
parent::__construct($configOrContainerInstance, $v3config);
54+
parent::__construct($configOrContainerInstance, $config);
5655
}
5756

5857
/**
59-
* Validate a plugin (v3)
58+
* Validate a plugin
6059
*
6160
* {@inheritDoc}
6261
*/
@@ -71,26 +70,6 @@ public function validate($plugin)
7170
}
7271
}
7372

74-
/**
75-
* Validate a plugin (v2)
76-
*
77-
* {@inheritDoc}
78-
*
79-
* @throws Exception\InvalidControllerException
80-
*/
81-
public function validatePlugin($plugin)
82-
{
83-
try {
84-
$this->validate($plugin);
85-
} catch (InvalidServiceException $e) {
86-
throw new Exception\InvalidControllerException(
87-
$e->getMessage(),
88-
$e->getCode(),
89-
$e
90-
);
91-
}
92-
}
93-
9473
/**
9574
* Initializer: inject EventManager instance
9675
*
@@ -101,63 +80,33 @@ public function validatePlugin($plugin)
10180
* the shared EM injection needs to happen; the conditional will always
10281
* pass.
10382
*
104-
* @param ContainerInterface|DispatchableInterface $first Container when
105-
* using zend-servicemanager v3; controller under v2.
106-
* @param DispatchableInterface|ContainerInterface $second Controller when
107-
* using zend-servicemanager v3; container under v2.
83+
* @param ContainerInterface $container
84+
* @param DispatchableInterface $controller
10885
*/
109-
public function injectEventManager($first, $second)
86+
public function injectEventManager(ContainerInterface $container, $controller)
11087
{
111-
if ($first instanceof ContainerInterface) {
112-
$container = $first;
113-
$controller = $second;
114-
} else {
115-
$container = $second;
116-
$controller = $first;
117-
}
118-
11988
if (! $controller instanceof EventManagerAwareInterface) {
12089
return;
12190
}
12291

12392
$events = $controller->getEventManager();
12493
if (! $events || ! $events->getSharedManager() instanceof SharedEventManagerInterface) {
125-
// For v2, we need to pull the parent service locator
126-
if (! method_exists($container, 'configure')) {
127-
$container = $container->getServiceLocator() ?: $container;
128-
}
129-
13094
$controller->setEventManager($container->get('EventManager'));
13195
}
13296
}
13397

13498
/**
13599
* Initializer: inject plugin manager
136100
*
137-
* @param ContainerInterface|DispatchableInterface $first Container when
138-
* using zend-servicemanager v3; controller under v2.
139-
* @param DispatchableInterface|ContainerInterface $second Controller when
140-
* using zend-servicemanager v3; container under v2.
101+
* @param ContainerInterface $container
102+
* @param DispatchableInterface $controller
141103
*/
142-
public function injectPluginManager($first, $second)
104+
public function injectPluginManager(ContainerInterface $container, $controller)
143105
{
144-
if ($first instanceof ContainerInterface) {
145-
$container = $first;
146-
$controller = $second;
147-
} else {
148-
$container = $second;
149-
$controller = $first;
150-
}
151-
152106
if (! method_exists($controller, 'setPluginManager')) {
153107
return;
154108
}
155109

156-
// For v2, we need to pull the parent service locator
157-
if (! method_exists($container, 'configure')) {
158-
$container = $container->getServiceLocator() ?: $container;
159-
}
160-
161110
$controller->setPluginManager($container->get('ControllerPluginManager'));
162111
}
163112
}

src/Controller/Plugin/Forward.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,9 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
180180
$results[$id][$eventName] = [];
181181
$events = $this->getSharedListenersById($id, $eventName, $sharedEvents);
182182
foreach ($events as $priority => $currentPriorityEvents) {
183-
// v2 fix
184-
if (!is_array($currentPriorityEvents)) {
185-
$currentPriorityEvents = [$currentPriorityEvents];
186-
}
187-
// v3
188183
foreach ($currentPriorityEvents as $currentEvent) {
189184
$currentCallback = $currentEvent;
190185

191-
// zend-eventmanager v2 compatibility:
192-
if ($currentCallback instanceof CallbackHandler) {
193-
$currentCallback = $currentEvent->getCallback();
194-
$priority = $currentEvent->getMetadatum('priority');
195-
}
196-
197186
// If we have an array, grab the object
198187
if (is_array($currentCallback)) {
199188
$currentCallback = array_shift($currentCallback);
@@ -203,16 +192,6 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
203192
if (!is_object($currentCallback)) {
204193
continue;
205194
}
206-
207-
foreach ($classArray as $class) {
208-
if ($currentCallback instanceof $class) {
209-
// Pass $currentEvent; when using zend-eventmanager v2,
210-
// this is the CallbackHandler, while in v3 it's
211-
// the actual listener.
212-
$this->detachSharedListener($id, $currentEvent, $sharedEvents);
213-
$results[$id][$eventName][$priority] = $currentEvent;
214-
}
215-
}
216195
}
217196
}
218197
}
@@ -235,12 +214,6 @@ protected function reattachProblemListeners(SharedEvents $sharedEvents, array $l
235214
foreach ($callbacks as $priority => $current) {
236215
$callback = $current;
237216

238-
// zend-eventmanager v2 compatibility:
239-
if ($current instanceof CallbackHandler) {
240-
$callback = $current->getCallback();
241-
$priority = $current->getMetadatum('priority');
242-
}
243-
244217
$sharedEvents->attach($id, $eventName, $callback, $priority);
245218
}
246219
}
@@ -293,12 +266,6 @@ protected function getEvent()
293266
*/
294267
private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
295268
{
296-
if (method_exists($sharedEvents, 'attachAggregate')) {
297-
// v2
298-
return $sharedEvents->getListeners($id, $event) ?: [];
299-
}
300-
301-
// v3
302269
return $sharedEvents->getListeners([$id], $event);
303270
}
304271

@@ -314,13 +281,6 @@ private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
314281
*/
315282
private function detachSharedListener($id, $listener, SharedEvents $sharedEvents)
316283
{
317-
if (method_exists($sharedEvents, 'attachAggregate')) {
318-
// v2
319-
$sharedEvents->detach($id, $listener);
320-
return;
321-
}
322-
323-
// v3
324284
$sharedEvents->detach($listener, $id);
325285
}
326286
}

src/Controller/Plugin/Service/ForwardFactory.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
namespace Zend\Mvc\Controller\Plugin\Service;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
14-
use Zend\ServiceManager\FactoryInterface;
15-
use Zend\ServiceManager\ServiceLocatorInterface;
1613
use Zend\Mvc\Controller\Plugin\Forward;
14+
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
15+
use Zend\ServiceManager\Factory\FactoryInterface;
1716

1817
class ForwardFactory implements FactoryInterface
1918
{
@@ -36,18 +35,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3635

3736
return new Forward($controllers);
3837
}
39-
40-
/**
41-
* Create and return Forward instance
42-
*
43-
* For use with zend-servicemanager v2; proxies to __invoke().
44-
*
45-
* @param ServiceLocatorInterface $container
46-
* @return Forward
47-
*/
48-
public function createService(ServiceLocatorInterface $container)
49-
{
50-
$parentContainer = $container->getServiceLocator() ?: $container;
51-
return $this($parentContainer, Forward::class);
52-
}
5338
}

src/Controller/PluginManager.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Zend\Mvc\Controller;
1111

12-
use Zend\Mvc\Exception;
1312
use Zend\ServiceManager\AbstractPluginManager;
1413
use Zend\ServiceManager\Exception\InvalidServiceException;
1514
use Zend\ServiceManager\Factory\InvokableFactory;
@@ -148,7 +147,7 @@ public function injectController($plugin)
148147
}
149148

150149
/**
151-
* Validate a plugin (v3)
150+
* Validate a plugin
152151
*
153152
* {@inheritDoc}
154153
*/
@@ -162,24 +161,4 @@ public function validate($plugin)
162161
));
163162
}
164163
}
165-
166-
/**
167-
* Validate a plugin (v2)
168-
*
169-
* {@inheritDoc}
170-
*
171-
* @throws Exception\InvalidPluginException
172-
*/
173-
public function validatePlugin($plugin)
174-
{
175-
try {
176-
$this->validate($plugin);
177-
} catch (InvalidServiceException $e) {
178-
throw new Exception\InvalidPluginException(
179-
$e->getMessage(),
180-
$e->getCode(),
181-
$e
182-
);
183-
}
184-
}
185164
}

src/Service/AbstractPluginManagerFactory.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
use Interop\Container\ContainerInterface;
1313
use Zend\ServiceManager\AbstractPluginManager;
14-
use Zend\ServiceManager\FactoryInterface;
15-
use Zend\ServiceManager\ServiceLocatorInterface;
14+
use Zend\ServiceManager\Factory\FactoryInterface;
1615

1716
abstract class AbstractPluginManagerFactory implements FactoryInterface
1817
{
@@ -35,17 +34,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3534
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
3635
return new $pluginManagerClass($container, $options);
3736
}
38-
39-
/**
40-
* Create and return AbstractPluginManager instance
41-
*
42-
* For use with zend-servicemanager v2; proxies to __invoke().
43-
*
44-
* @param ServiceLocatorInterface $container
45-
* @return AbstractPluginManager
46-
*/
47-
public function createService(ServiceLocatorInterface $container)
48-
{
49-
return $this($container, AbstractPluginManager::class);
50-
}
5137
}

src/Service/ApplicationFactory.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
use Interop\Container\ContainerInterface;
1313
use Zend\Mvc\Application;
14-
use Zend\ServiceManager\FactoryInterface;
15-
use Zend\ServiceManager\ServiceLocatorInterface;
14+
use Zend\ServiceManager\Factory\FactoryInterface;
1615

1716
class ApplicationFactory implements FactoryInterface
1817
{
1918
/**
20-
* Create the Application service (v3)
19+
* Create the Application service
2120
*
2221
* Creates a Zend\Mvc\Application service, passing it the configuration
2322
* service and the service manager instance.
@@ -36,17 +35,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3635
$container->get('Response')
3736
);
3837
}
39-
40-
/**
41-
* Create the Application service (v2)
42-
*
43-
* Proxies to __invoke().
44-
*
45-
* @param ServiceLocatorInterface $container
46-
* @return Application
47-
*/
48-
public function createService(ServiceLocatorInterface $container)
49-
{
50-
return $this($container, Application::class);
51-
}
5238
}

src/Service/ConfigFactory.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace Zend\Mvc\Service;
1111

1212
use Interop\Container\ContainerInterface;
13-
use Zend\ServiceManager\FactoryInterface;
14-
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Traversable;
14+
use Zend\ServiceManager\Factory\FactoryInterface;
1515

1616
class ConfigFactory implements FactoryInterface
1717
{
@@ -27,7 +27,7 @@ class ConfigFactory implements FactoryInterface
2727
* @param ContainerInterface $container
2828
* @param string $name
2929
* @param null|array $options
30-
* @return array|\Traversable
30+
* @return array|Traversable
3131
*/
3232
public function __invoke(ContainerInterface $container, $name, array $options = null)
3333
{
@@ -36,17 +36,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3636
$moduleParams = $moduleManager->getEvent()->getParams();
3737
return $moduleParams['configListener']->getMergedConfig(false);
3838
}
39-
40-
/**
41-
* Create and return config instance
42-
*
43-
* For use with zend-servicemanager v2; proxies to __invoke().
44-
*
45-
* @param ServiceLocatorInterface $container
46-
* @return array|\Traversable
47-
*/
48-
public function createService(ServiceLocatorInterface $container)
49-
{
50-
return $this($container, 'config');
51-
}
5239
}

0 commit comments

Comments
 (0)