Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Symfony HandleTrait #207

Closed
alexander-schranz opened this issue Nov 11, 2021 · 5 comments
Closed

Support for Symfony HandleTrait #207

alexander-schranz opened this issue Nov 11, 2021 · 5 comments

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Nov 11, 2021

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.

@bnowak
Copy link
Contributor

bnowak commented Apr 5, 2024

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

@bnowak
Copy link
Contributor

bnowak commented Apr 5, 2024

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
Copy link
Contributor

bnowak commented Oct 17, 2024

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
Copy link
Contributor

bnowak commented Oct 17, 2024

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
Copy link
Member

Implemented #404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants