Skip to content

Commit 733205b

Browse files
committed
[Workflow] Add some PHP attributes to register listeners and guards
1 parent ed99531 commit 733205b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,29 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11091109
$container->setParameter('workflow.has_guard_listeners', true);
11101110
}
11111111
}
1112+
1113+
$listenerAttributes = [
1114+
Workflow\Attribute\AsAnnounceListener::class,
1115+
Workflow\Attribute\AsCompletedListener::class,
1116+
Workflow\Attribute\AsEnterListener::class,
1117+
Workflow\Attribute\AsEnteredListener::class,
1118+
Workflow\Attribute\AsGuardListener::class,
1119+
Workflow\Attribute\AsLeaveListener::class,
1120+
Workflow\Attribute\AsTransitionListener::class,
1121+
];
1122+
1123+
foreach ($listenerAttributes as $attribute) {
1124+
$container->registerAttributeForAutoconfiguration($attribute, static function (ChildDefinition $definition, AsEventListener $attribute, \ReflectionClass|\ReflectionMethod $reflector) {
1125+
$tagAttributes = get_object_vars($attribute);
1126+
if ($reflector instanceof \ReflectionMethod) {
1127+
if (isset($tagAttributes['method'])) {
1128+
throw new LogicException(sprintf('"%s" attribute cannot declare a method on "%s::%s()".', $attribute::class, $reflector->class, $reflector->name));
1129+
}
1130+
$tagAttributes['method'] = $reflector->getName();
1131+
}
1132+
$definition->addTag('kernel.event_listener', $tagAttributes);
1133+
});
1134+
}
11121135
}
11131136

11141137
private function registerDebugConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void

0 commit comments

Comments
 (0)