From d7f36a7ee0cb76b1740c4416c44eb3d4e0555f90 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 1/4] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 00837045..0138f8f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From f0ae1383a8285dfc6752b8d8602790953118ff5a Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 2/4] Migrate to `static` data providers using `rector/rector` --- Tests/Debug/WrappedListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Debug/WrappedListenerTest.php b/Tests/Debug/WrappedListenerTest.php index 6564d23f..68db87db 100644 --- a/Tests/Debug/WrappedListenerTest.php +++ b/Tests/Debug/WrappedListenerTest.php @@ -28,7 +28,7 @@ public function testListenerDescription($listener, $expected) $this->assertStringMatchesFormat($expected, $wrappedListener->getPretty()); } - public function provideListenersToDescribe() + public static function provideListenersToDescribe() { return [ [new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'], From 57b312f7fcb07f710d900c7e6f95cb883d2bfda1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 6 Mar 2023 20:53:37 +0100 Subject: [PATCH 3/4] [Translation] Decouple TranslatorPathsPass from "debug." convention --- DependencyInjection/RegisterListenersPass.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/RegisterListenersPass.php b/DependencyInjection/RegisterListenersPass.php index 8eabe7d7..f47120db 100644 --- a/DependencyInjection/RegisterListenersPass.php +++ b/DependencyInjection/RegisterListenersPass.php @@ -122,7 +122,7 @@ public function process(ContainerBuilder $container) $dispatcherDefinition = $globalDispatcherDefinition; if (isset($event['dispatcher'])) { - $dispatcherDefinition = $container->getDefinition($event['dispatcher']); + $dispatcherDefinition = $container->findDefinition($event['dispatcher']); } $dispatcherDefinition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]); @@ -161,7 +161,7 @@ public function process(ContainerBuilder $container) continue; } - $dispatcherDefinitions[$attributes['dispatcher']] = $container->getDefinition($attributes['dispatcher']); + $dispatcherDefinitions[$attributes['dispatcher']] = $container->findDefinition($attributes['dispatcher']); } if (!$dispatcherDefinitions) { From 1df20e45d56da29a4b1d8259dd6e950acbf1b13f Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Thu, 16 Mar 2023 16:48:23 +0100 Subject: [PATCH 4/4] Stop stopwatch events in case of exception --- Debug/WrappedListener.php | 10 ++++++---- Tests/Debug/WrappedListenerTest.php | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Debug/WrappedListener.php b/Debug/WrappedListener.php index 86d3854b..3c4cc133 100644 --- a/Debug/WrappedListener.php +++ b/Debug/WrappedListener.php @@ -114,10 +114,12 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf $e = $this->stopwatch->start($this->name, 'event_listener'); - ($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher); - - if ($e->isStarted()) { - $e->stop(); + try { + ($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher); + } finally { + if ($e->isStarted()) { + $e->stop(); + } } if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) { diff --git a/Tests/Debug/WrappedListenerTest.php b/Tests/Debug/WrappedListenerTest.php index 68db87db..115657ea 100644 --- a/Tests/Debug/WrappedListenerTest.php +++ b/Tests/Debug/WrappedListenerTest.php @@ -15,6 +15,7 @@ use Symfony\Component\EventDispatcher\Debug\WrappedListener; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Stopwatch\Stopwatch; +use Symfony\Component\Stopwatch\StopwatchEvent; class WrappedListenerTest extends TestCase { @@ -42,6 +43,25 @@ public static function provideListenersToDescribe() [\Closure::fromCallable(function () {}), 'closure'], ]; } + + public function testStopwatchEventIsStoppedWhenListenerThrows() + { + $stopwatchEvent = $this->createMock(StopwatchEvent::class); + $stopwatchEvent->expects(self::once())->method('isStarted')->willReturn(true); + $stopwatchEvent->expects(self::once())->method('stop'); + + $stopwatch = $this->createStub(Stopwatch::class); + $stopwatch->method('start')->willReturn($stopwatchEvent); + + $dispatcher = $this->createStub(EventDispatcherInterface::class); + + $wrappedListener = new WrappedListener(function () { throw new \Exception(); }, null, $stopwatch, $dispatcher); + + try { + $wrappedListener(new \stdClass(), 'foo', $dispatcher); + } catch (\Exception $ex) { + } + } } class FooListener