diff --git a/library/Zend/Mvc/Controller/Plugin/Forward.php b/library/Zend/Mvc/Controller/Plugin/Forward.php index 4f48cf2c77a..78dc1b6791b 100644 --- a/library/Zend/Mvc/Controller/Plugin/Forward.php +++ b/library/Zend/Mvc/Controller/Plugin/Forward.php @@ -176,11 +176,19 @@ protected function detachProblemListeners(SharedEvents $sharedEvents) $events = $sharedEvents->getListeners($id, $eventName); foreach ($events as $currentEvent) { $currentCallback = $currentEvent->getCallback(); - if (!isset($currentCallback[0])) { + + // If we have an array, grab the object + if (is_array($currentCallback)) { + $currentCallback = array_shift($currentCallback); + } + + // This routine is only valid for object callbacks + if (!is_object($currentCallback)) { continue; } + foreach ($classArray as $class) { - if (is_a($currentCallback[0], $class)) { + if (is_a($currentCallback, $class)) { $sharedEvents->detach($id, $currentEvent); $results[$id][$eventName][] = $currentEvent; } diff --git a/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php b/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php index 4debb6e9dcf..f87a662980f 100644 --- a/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php +++ b/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php @@ -19,6 +19,7 @@ use Zend\Mvc\Controller\Plugin\Forward as ForwardPlugin; use Zend\Mvc\MvcEvent; use Zend\Mvc\Router\RouteMatch; +use Zend\Stdlib\CallbackHandler; use ZendTest\Mvc\Controller\TestAsset\ForwardController; use ZendTest\Mvc\Controller\TestAsset\SampleController; use ZendTest\Mvc\Controller\TestAsset\UneventfulController; @@ -128,6 +129,29 @@ public function testPluginDispatchsRequestedControllerWhenFound() $this->assertEquals(array('content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'), $result); } + /** + * @group 5432 + */ + public function testNonArrayListenerDoesNotRaiseErrorWhenPluginDispatchsRequestedController() + { + $services = $this->plugins->getServiceLocator(); + $events = $services->get('EventManager'); + $sharedEvents = $this->getMock('Zend\EventManager\SharedEventManagerInterface'); + $sharedEvents->expects($this->any())->method('getListeners')->will($this->returnValue(array( + new CallbackHandler(function ($e) {}) + ))); + $events = $this->getMock('Zend\EventManager\EventManagerInterface'); + $events->expects($this->any())->method('getSharedManager')->will($this->returnValue($sharedEvents)); + $application = $this->getMock('Zend\Mvc\ApplicationInterface'); + $application->expects($this->any())->method('getEventManager')->will($this->returnValue($events)); + $event = $this->controller->getEvent(); + $event->setApplication($application); + + $result = $this->plugin->dispatch('forward'); + $this->assertInternalType('array', $result); + $this->assertEquals(array('content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'), $result); + } + public function testDispatchWillSeedRouteMatchWithPassedParameters() { $result = $this->plugin->dispatch('forward', array(