Skip to content

Commit b3b4387

Browse files
authored
fix: support named arguments in BufferFlushPass (#948)
1 parent 915ec90 commit b3b4387

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/DependencyInjection/Compiler/BufferFlushPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private function findSentryBufferHandlers(ContainerBuilder $container): array
4545
$arguments = $definition->getArguments();
4646
if (!empty($arguments)) {
4747
// The first argument of BufferHandler is the HandlerInterface, which
48-
// can be a SentryHandler.
49-
$firstArgument = $arguments[0];
48+
// can be a SentryHandler. Missing argument will be ignored.
49+
$firstArgument = $arguments[0] ?? $arguments['$handler'] ?? null;
5050

5151
if ($firstArgument instanceof Reference) {
5252
$referencedServiceId = (string) $firstArgument;

tests/DependencyInjection/Compiler/BufferFlushPassTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,21 @@ public function testProcessWithFakeSentryHandlers()
116116
$serviceIds = $this->argumentToName($definition);
117117
$this->assertEquals(['sentry.test.handler'], $serviceIds);
118118
}
119+
120+
/**
121+
* Test that the flusher will work with named arguments.
122+
*
123+
* @return void
124+
*/
125+
public function testProcessWithNamedArguments()
126+
{
127+
$container = new ContainerBuilder();
128+
$container->setDefinition('sentry.handler', new Definition(SentryHandler::class));
129+
$container->setDefinition('sentry.test.handler', new Definition(BufferHandler::class, ['$handler' => new Reference('sentry.handler')]));
130+
131+
(new BufferFlushPass())->process($container);
132+
$definition = $container->getDefinition('sentry.buffer_flusher');
133+
$serviceIds = $this->argumentToName($definition);
134+
$this->assertEquals(['sentry.test.handler'], $serviceIds);
135+
}
119136
}

0 commit comments

Comments
 (0)