Skip to content

Support for Symfony HandleTrait #207

Closed
@alexander-schranz

Description

@alexander-schranz
Contributor

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.

Activity

bnowak

bnowak commented on Apr 5, 2024

@bnowak
Contributor

Did anybody take a look on that so far to give some insights? Today, I'm going to start working on this.

bnowak

bnowak commented on Apr 5, 2024

@bnowak
Contributor

So far, I researched that in current version not having of this feature request, it could be a blocker.

but I'm keep digging 😉

bnowak

bnowak commented on Oct 17, 2024

@bnowak
Contributor

I'm happy to announce that PR for that is done and ready for review here :)

Feel free to review and give your feedback, thank you :)

bnowak

bnowak commented on Oct 17, 2024

@bnowak
Contributor

There's also another QueryBus-classes related topic which I wanted to cover with reusing this feature. It's described in this comment. If you have idea how to solve it, please share it here :) Thanks, again

ondrejmirtes

ondrejmirtes commented on Jan 4, 2025

@ondrejmirtes
Member

Implemented #404

github-actions

github-actions commented on Feb 5, 2025

@github-actions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

locked as resolved and limited conversation to collaborators on Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ondrejmirtes@alexander-schranz@bnowak

        Issue actions

          Support for Symfony HandleTrait · Issue #207 · phpstan/phpstan-symfony