8000 [DoctrineBridge] Param as connection in `*.event_subscriber/listener` tags by wbloszyk · Pull Request #40262 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Param as connection in *.event_subscriber/listener tags #40262

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2021
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
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ private function addTaggedServices(ContainerBuilder $container): array
$managerDefs = [];
foreach ($taggedServices as $taggedSubscriber) {
[$tagName, $id, $tag] = $taggedSubscriber;
$connections = isset($tag['connection']) ? [$tag['connection']] : array_keys($this->connections);
$connections = isset($tag['connection'])
? [$container->getParameterBag()->resolveValue($tag['connection'])]
: array_keys($this->connections);
if ($listenerTag === $tagName && !isset($tag['event'])) {
throw new InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
}
Expand Down
Original file line number Diff line number Diff line change
10000 Expand Up @@ -114,6 +114,8 @@ public function testProcessEventListenersWithMultipleConnections()
{
$container = $this->createBuilder(true);

$container->setParameter('connection_param', 'second');

$container
->register('a', 'stdClass')
->addTag('doctrine.event_listener', [
Expand All @@ -137,6 +139,14 @@ public function testProcessEventListenersWithMultipleConnections()
])
;

$container
->register('d', 'stdClass')
->addTag('doctrine.event_listener', [
'event' => 'onFlush',
'connection' => '%connection_param%',
])
;

$this->process($container);

$eventManagerDef = $container->getDefinition('doctrine.dbal.default_connection.event_manager');
Expand Down Expand Up @@ -167,6 +177,7 @@ public function testProcessEventListenersWithMultipleConnections()
[
[['onFlush'], 'a'],
[['onFlush'], 'c'],
[['onFlush'], 'd'],
],
$secondEventManagerDef->getArgument(1)
);
Expand All @@ -178,6 +189,7 @@ public function testProcessEventListenersWithMultipleConnections()
[
'a' => new ServiceClosureArgument(new Reference('a')),
'c' => new ServiceClosureArgument(new Reference('c')),
'd' => new ServiceClosureArgument(new Reference('d')),
],
$serviceLocatorDef->getArgument(0)
);
Expand All @@ -187,6 +199,8 @@ public function testProcessEventSubscribersWithMultipleConnections()
{
$container = $this->createBuilder(true);

$container->setParameter('connection_param', 'second');

$container
->register('a', 'stdClass')
->addTag('doctrine.event_subscriber', [
Expand All @@ -210,6 +224,14 @@ public function testProcessEventSubscribersWithMultipleConnections()
])
;

$container
->register('d', 'stdClass')
->addTag('doctrine.event_subscriber', [
'event' => 'onFlush',
'connection' => '%connection_param%',
])
;

$this->process($container);

$eventManagerDef = $container->getDefinition('doctrine.dbal.default_connection.event_manager');
Expand Down Expand Up @@ -240,6 +262,7 @@ public function testProcessEventSubscribersWithMultipleConnections()
[
'a',
'c',
'd',
],
$eventManagerDef->getArgument(1)
);
Expand All @@ -250,6 +273,7 @@ public function testProcessEventSubscribersWithMultipleConnections()
[
'a' => new ServiceClosureArgument(new Reference('a')),
'c' => new ServiceClosureArgument(new Reference('c')),
'd' => new ServiceClosureArgument(new Reference('d')),
],
$serviceLocatorDef->getArgument(0)
);
Expand Down
0