Skip to content

Commit

Permalink
Make trait internal, improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
squrious committed Mar 20, 2024
1 parent 3fb63f1 commit 6ef6cb5
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Symfony/Component/Workflow/Event/EventNameTrait.php
Expand Up @@ -15,19 +15,11 @@

/**
* @author Nicolas Rigaud <squrious@protonmail.com>
*
* @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.
*
Expand All @@ -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);
}
}

0 comments on commit 6ef6cb5

Please sign in to comment.