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

New command - make:message for Messenger #338

Merged
merged 5 commits into from
Mar 28, 2020

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Dec 20, 2018

An easy one - generated for Messenger - generates an empty message class and corresponding handler:

screen shot 2018-12-20 at 2 23 54 pm

Generated Code

SendWelcomeEmailMessage

<?php

namespace App\Message;

class SendWelcomeEmailMessage
{
    /*
     * Add whatever properties & methods you need to hold the
     * data for this message class.
     *
     * Note - if you're handling this message async, you may need
     * a getter & setter method for each property so that it serializes
     * and unserializes correctly.
     */

//     private $name;
//
//     public function __construct(string $name)
//     {
//         $this->name = $name;
//     }
//
//    public function getName(): string
//    {
//        return $this->name;
//    }
//
//    public function setName(string $name)
//    {
//        $this->name = $name;
//    }
}

SendWelcomeEmailMessageHandler

<?php

namespace App\MessageHandler;

use App\Message\SendWelcomeEmailMessage;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class SendWelcomeEmailMessageHandler implements MessageHandlerInterface
{
    public function __invoke(SendWelcomeEmailMessage $message)
    {
        // do something with your message
    }
}

In the future... we could possibly ask which transport you want to use and update your YAML configuration (if needed) 🤔

@weaverryan weaverryan force-pushed the make-message branch 2 times, most recently from a9e46bf to 891552e Compare December 21, 2018 01:41
class <?= $class_name."\n" ?>
{
/*
* Add whatever properties & methods you need to hold the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about doing it like in the make entity command, one could nearly reuse the existing code without the annotations stuff. This would make it more handy imo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you point what part of command or entity can be reused? :)


namespace <?= $namespace; ?>;

class <?= $class_name."\n" ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind making this final?

use <?= $message_full_class_name ?>;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class <?= $class_name ?> implements MessageHandlerInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final, too?

// return $this->name;
// }
//
// public function setName(string $name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be preferable to keep messages immutable. What about not promoting setters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 💡

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to remove the setter example

* Note - if you're handling this message async, you may need
* a getter & setter method for each property so that it serializes
* and unserializes correctly.
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment can now be removed

// return $this->name;
// }
//
// public function setName(string $name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to remove the setter example

@nikophil nikophil force-pushed the make-message branch 2 times, most recently from 22348e9 to e34533a Compare December 11, 2019 16:51
@nikophil
Copy link
Contributor

Hi,

according to a chat i had with @weaverryan i've completed this maker in order to allow the user to route the message to a transport

Capture du 2019-12-11 17-53-23

@OskarStark
Copy link
Contributor

I am routing my Messages based on an „AsyncMessage“-Marker Interface, is it worth to add such an option instead of manipulating the messenger.yaml file?

@weaverryan
Copy link
Member Author

It’s a very interesting idea... but I don’t think it’s standard enough yet to put into maker. Better to show them where/how routing happens

@nikophil
Copy link
Contributor

i kinda agree with @weaverryan. Although it is a nice trick, it may involve too much complexity and different cases to handle in the maker.

BTW, the CI is failing because of some deprecation i fixed here: #518

@weaverryan
Copy link
Member Author

Thank you for taking this across the finish line @nikophil!

@weaverryan weaverryan merged commit fe4a63c into symfony:master Mar 28, 2020
@OskarStark
Copy link
Contributor

Nice, when can we expect a release? 😊😎

@weaverryan weaverryan deleted the make-message branch March 28, 2020 13:57
@weaverryan
Copy link
Member Author

Soon! Finishing the new reset password stuff!

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

Successfully merging this pull request may close these issues.

None yet

5 participants