Skip to content

Commit 18125d6

Browse files
committed
Merge branch 'feature/194-clear-event-stop-propagation' into develop
Close #194
2 parents a60b19e + 45edc58 commit 18125d6

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#194](https://github.com/zfcampus/zf-apigility/pull/194) fixes an issue within `Zend\Apigility\Application` whereby it was not
26+
clearing the "stop propagation" flag prior to triggering new events.
2627

2728
## 1.3.0 - 2016-07-28
2829

src/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function run()
5555

5656
// Trigger route event
5757
$event->setName(MvcEvent::EVENT_ROUTE);
58+
$event->stopPropagation(false); // Clear before triggering
5859
try {
5960
$result = $events->triggerEventUntil($shortCircuit, $event);
6061
} catch (Throwable $e) {
@@ -69,6 +70,7 @@ public function run()
6970
$event->setName(MvcEvent::EVENT_FINISH);
7071
$event->setTarget($this);
7172
$event->setResponse($response);
73+
$event->stopPropagation(false); // Clear before triggering
7274
$events->triggerEvent($event);
7375
$this->response = $response;
7476
return $this;
@@ -81,6 +83,7 @@ public function run()
8183

8284
// Trigger dispatch event
8385
$event->setName(MvcEvent::EVENT_DISPATCH);
86+
$event->stopPropagation(false); // Clear before triggering
8487
$result = $events->triggerEventUntil($shortCircuit, $event);
8588

8689
// Complete response
@@ -89,6 +92,7 @@ public function run()
8992
$event->setName(MvcEvent::EVENT_FINISH);
9093
$event->setTarget($this);
9194
$event->setResponse($response);
95+
$event->stopPropagation(false); // Clear before triggering
9296
$events->triggerEvent($event);
9397
$this->response = $response;
9498
return $this;
@@ -113,6 +117,7 @@ private function handleException($exception, MvcEvent $event, EventManagerInterf
113117
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
114118
$event->setError(self::ERROR_EXCEPTION);
115119
$event->setParam('exception', $exception);
120+
$event->stopPropagation(false); // Clear before triggering
116121
$result = $events->triggerEvent($event);
117122

118123
$response = $result->last();
@@ -121,6 +126,7 @@ private function handleException($exception, MvcEvent $event, EventManagerInterf
121126
$event->setTarget($this);
122127
$event->setResponse($response);
123128
$this->response = $response;
129+
$event->stopPropagation(false); // Clear before triggering
124130
$events->triggerEvent($event);
125131
return $this;
126132
}

test/ApplicationTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\TestCase;
1111
use ReflectionMethod;
1212
use ReflectionProperty;
13+
use Zend\EventManager\EventInterface;
1314
use Zend\EventManager\EventManager;
1415
use Zend\Http\PhpEnvironment;
1516
use Zend\Mvc\MvcEvent;
@@ -121,4 +122,24 @@ public function testRouteListenerRaisingExceptionTriggersDispatchErrorAndSkipsDi
121122
$this->assertTrue($finishTriggered);
122123
$this->assertSame($response, $this->app->getResponse());
123124
}
125+
126+
public function testStopPropagationFromPrevEventShouldBeCleared()
127+
{
128+
$events = $this->app->getEventManager();
129+
$response = $this->prophesize(PhpEnvironment\Response::class)->reveal();
130+
131+
$events->attach('route', function (EventInterface $e) use ($response) {
132+
$e->stopPropagation(true);
133+
return $response;
134+
});
135+
136+
$isStopPropagation = null;
137+
$events->attach('finish', function (EventInterface $e) use (&$isStopPropagation) {
138+
$isStopPropagation = $e->propagationIsStopped();
139+
});
140+
141+
$this->app->run();
142+
143+
$this->assertFalse($isStopPropagation);
144+
}
124145
}

0 commit comments

Comments
 (0)