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

Problem with Forward Plugin #5432

Merged
merged 5 commits into from
Nov 12, 2013
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
12 changes: 10 additions & 2 deletions library/Zend/Mvc/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down