diff --git a/src/Symfony/Component/Workflow/Event/EventNameTrait.php b/src/Symfony/Component/Workflow/Event/EventNameTrait.php index 141a357a4e563..fbc557f0f5709 100644 --- a/src/Symfony/Component/Workflow/Event/EventNameTrait.php +++ b/src/Symfony/Component/Workflow/Event/EventNameTrait.php @@ -15,19 +15,11 @@ /** * @author Nicolas Rigaud + * + * @internal */ trait EventNameTrait { - /** - * Get the event name as lowercase string. - * - * Example: EnterEvent => enter - */ - public static function getName(): string - { - return strtolower(substr(substr(static::class, strrpos(static::class, '\\') + 1), 0, -5)); - } - /** * Get event name for workflow and transition. * @@ -50,10 +42,19 @@ private static function getNameForPlace(?string $workflowName, ?string $placeNam private static function computeName(?string $workflowName, ?string $transitionOrPlaceName): string { - if (null !== $transitionOrPlaceName && null === $workflowName) { - throw new \InvalidArgumentException('Missing workflow name.'); + $eventName = strtolower(basename(str_replace('\\', '/', static::class), 'Event')); + + if (null === $workflowName) { + if (null !== $transitionOrPlaceName) { + throw new \InvalidArgumentException('Missing workflow name.'); + } + return sprintf('workflow.%s', $eventName); + } + + if (null === $transitionOrPlaceName) { + return sprintf('workflow.%s.%s', $workflowName, $eventName); } - return implode('.', array_filter(['workflow', $workflowName, self::getName(), $transitionOrPlaceName], \is_string(...))); + return sprintf('workflow.%s.%s.%s', $workflowName, $eventName, $transitionOrPlaceName); } }