Description
I think it would be great if the extension could automatically recognize the type of HandleTrait
of symfony.
The given message to the handle trait example:
$this->handle(new CreateUserMessage());
does only have 1 Handler which return type the return type of the handle trait will be. Example:
class CreateUserMessageHandler {
public function __invoke(CreateUserMessage $message): User
{
return new User($message->getUserName());
}
}
The bin/console debug:messenger
already shows the mapping between Message and Handlers.
The HandleStamp
contains under the getResult
method the result of every handler: https://github.com/symfony/symfony/blob/8eed84bb2df613101949ca2e786ac383d2f349fd/src/Symfony/Component/Messenger/HandleTrait.php#L45. The HandleTrait only allows one handler per message, that make the result recognize able. Not sure if its even possible to overwrite the result of a trait. Sadly my skillset for providing this myself is to low, but would think it would be a great feature.
Currenty workaround is:
/** @var User */
$user = $this->handle(new CreateUserMessage());
The first parameter of console.command.messenger_debug
service would contain the mapping between message and handler so we can guess the type from there.