Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ All notable changes to this project will be documented in this file, in reverse

### Removed

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

### Fixed

Expand Down
71 changes: 10 additions & 61 deletions src/Controller/ControllerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Interop\Container\ContainerInterface;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\Mvc\Exception;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\ConfigInterface;
use Zend\ServiceManager\Exception\InvalidServiceException;
Expand Down Expand Up @@ -46,17 +45,17 @@ class ControllerManager extends AbstractPluginManager
* event manager and plugin manager.
*
* @param ConfigInterface|ContainerInterface $container
* @param array $v3config
* @param array $config
*/
public function __construct($configOrContainerInstance, array $v3config = [])
public function __construct($configOrContainerInstance, array $config = [])
{
$this->addInitializer([$this, 'injectEventManager']);
$this->addInitializer([$this, 'injectPluginManager']);
parent::__construct($configOrContainerInstance, $v3config);
parent::__construct($configOrContainerInstance, $config);
}

/**
* Validate a plugin (v3)
* Validate a plugin
*
* {@inheritDoc}
*/
Expand All @@ -71,26 +70,6 @@ public function validate($plugin)
}
}

/**
* Validate a plugin (v2)
*
* {@inheritDoc}
*
* @throws Exception\InvalidControllerException
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidControllerException(
$e->getMessage(),
$e->getCode(),
$e
);
}
}

/**
* Initializer: inject EventManager instance
*
Expand All @@ -101,63 +80,33 @@ public function validatePlugin($plugin)
* the shared EM injection needs to happen; the conditional will always
* pass.
*
* @param ContainerInterface|DispatchableInterface $first Container when
* using zend-servicemanager v3; controller under v2.
* @param DispatchableInterface|ContainerInterface $second Controller when
* using zend-servicemanager v3; container under v2.
* @param ContainerInterface $container
* @param DispatchableInterface $controller
*/
public function injectEventManager($first, $second)
public function injectEventManager(ContainerInterface $container, $controller)
{
if ($first instanceof ContainerInterface) {
$container = $first;
$controller = $second;
} else {
$container = $second;
$controller = $first;
}

if (! $controller instanceof EventManagerAwareInterface) {
return;
}

$events = $controller->getEventManager();
if (! $events || ! $events->getSharedManager() instanceof SharedEventManagerInterface) {
// For v2, we need to pull the parent service locator
if (! method_exists($container, 'configure')) {
$container = $container->getServiceLocator() ?: $container;
}

$controller->setEventManager($container->get('EventManager'));
}
}

/**
* Initializer: inject plugin manager
*
* @param ContainerInterface|DispatchableInterface $first Container when
* using zend-servicemanager v3; controller under v2.
* @param DispatchableInterface|ContainerInterface $second Controller when
* using zend-servicemanager v3; container under v2.
* @param ContainerInterface $container
* @param DispatchableInterface $controller
*/
public function injectPluginManager($first, $second)
public function injectPluginManager(ContainerInterface $container, $controller)
{
if ($first instanceof ContainerInterface) {
$container = $first;
$controller = $second;
} else {
$container = $second;
$controller = $first;
}

if (! method_exists($controller, 'setPluginManager')) {
return;
}

// For v2, we need to pull the parent service locator
if (! method_exists($container, 'configure')) {
$container = $container->getServiceLocator() ?: $container;
}

$controller->setPluginManager($container->get('ControllerPluginManager'));
}
}
40 changes: 0 additions & 40 deletions src/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,9 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
$results[$id][$eventName] = [];
$events = $this->getSharedListenersById($id, $eventName, $sharedEvents);
foreach ($events as $priority => $currentPriorityEvents) {
// v2 fix
if (!is_array($currentPriorityEvents)) {
$currentPriorityEvents = [$currentPriorityEvents];
}
// v3
foreach ($currentPriorityEvents as $currentEvent) {
$currentCallback = $currentEvent;

// zend-eventmanager v2 compatibility:
if ($currentCallback instanceof CallbackHandler) {
$currentCallback = $currentEvent->getCallback();
$priority = $currentEvent->getMetadatum('priority');
}

// If we have an array, grab the object
if (is_array($currentCallback)) {
$currentCallback = array_shift($currentCallback);
Expand All @@ -203,16 +192,6 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
if (!is_object($currentCallback)) {
continue;
}

foreach ($classArray as $class) {
if ($currentCallback instanceof $class) {
// Pass $currentEvent; when using zend-eventmanager v2,
// this is the CallbackHandler, while in v3 it's
// the actual listener.
$this->detachSharedListener($id, $currentEvent, $sharedEvents);
$results[$id][$eventName][$priority] = $currentEvent;
}
}
}
}
}
Expand All @@ -235,12 +214,6 @@ protected function reattachProblemListeners(SharedEvents $sharedEvents, array $l
foreach ($callbacks as $priority => $current) {
$callback = $current;

// zend-eventmanager v2 compatibility:
if ($current instanceof CallbackHandler) {
$callback = $current->getCallback();
$priority = $current->getMetadatum('priority');
}

$sharedEvents->attach($id, $eventName, $callback, $priority);
}
}
Expand Down Expand Up @@ -293,12 +266,6 @@ protected function getEvent()
*/
private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
{
if (method_exists($sharedEvents, 'attachAggregate')) {
// v2
return $sharedEvents->getListeners($id, $event) ?: [];
}

// v3
return $sharedEvents->getListeners([$id], $event);
}

Expand All @@ -314,13 +281,6 @@ private function getSharedListenersById($id, $event, SharedEvents $sharedEvents)
*/
private function detachSharedListener($id, $listener, SharedEvents $sharedEvents)
{
if (method_exists($sharedEvents, 'attachAggregate')) {
// v2
$sharedEvents->detach($id, $listener);
return;
}

// v3
$sharedEvents->detach($listener, $id);
}
}
19 changes: 2 additions & 17 deletions src/Controller/Plugin/Service/ForwardFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
namespace Zend\Mvc\Controller\Plugin\Service;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Mvc\Controller\Plugin\Forward;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Factory\FactoryInterface;

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

return new Forward($controllers);
}

/**
* Create and return Forward instance
*
* For use with zend-servicemanager v2; proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return Forward
*/
public function createService(ServiceLocatorInterface $container)
{
$parentContainer = $container->getServiceLocator() ?: $container;
return $this($parentContainer, Forward::class);
}
}
23 changes: 1 addition & 22 deletions src/Controller/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Mvc\Controller;

use Zend\Mvc\Exception;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;
Expand Down Expand Up @@ -148,7 +147,7 @@ public function injectController($plugin)
}

/**
* Validate a plugin (v3)
* Validate a plugin
*
* {@inheritDoc}
*/
Expand All @@ -162,24 +161,4 @@ public function validate($plugin)
));
}
}

/**
* Validate a plugin (v2)
*
* {@inheritDoc}
*
* @throws Exception\InvalidPluginException
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidPluginException(
$e->getMessage(),
$e->getCode(),
$e
);
}
}
}
16 changes: 1 addition & 15 deletions src/Service/AbstractPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

abstract class AbstractPluginManagerFactory implements FactoryInterface
{
Expand All @@ -35,17 +34,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
return new $pluginManagerClass($container, $options);
}

/**
* Create and return AbstractPluginManager instance
*
* For use with zend-servicemanager v2; proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return AbstractPluginManager
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, AbstractPluginManager::class);
}
}
18 changes: 2 additions & 16 deletions src/Service/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

use Interop\Container\ContainerInterface;
use Zend\Mvc\Application;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

class ApplicationFactory implements FactoryInterface
{
/**
* Create the Application service (v3)
* Create the Application service
*
* Creates a Zend\Mvc\Application service, passing it the configuration
* service and the service manager instance.
Expand All @@ -36,17 +35,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
$container->get('Response')
);
}

/**
* Create the Application service (v2)
*
* Proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return Application
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, Application::class);
}
}
19 changes: 3 additions & 16 deletions src/Service/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Zend\Mvc\Service;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Traversable;
use Zend\ServiceManager\Factory\FactoryInterface;

class ConfigFactory implements FactoryInterface
{
Expand All @@ -27,7 +27,7 @@ class ConfigFactory implements FactoryInterface
* @param ContainerInterface $container
* @param string $name
* @param null|array $options
* @return array|\Traversable
* @return array|Traversable
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
Expand All @@ -36,17 +36,4 @@ public function __invoke(ContainerInterface $container, $name, array $options =
$moduleParams = $moduleManager->getEvent()->getParams();
return $moduleParams['configListener']->getMergedConfig(false);
}

/**
* Create and return config instance
*
* For use with zend-servicemanager v2; proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return array|\Traversable
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, 'config');
}
}
Loading