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

Dispatch Event after email sent + split Sender and Renderer #2482

Merged
merged 1 commit into from
Mar 25, 2015

Conversation

amenophis
Copy link
Contributor

As disscussed here: #2479
This is a first implementation.

@pjedrzejewski can you feedback ?

@amenophis amenophis force-pushed the mailer-event branch 3 times, most recently from ad34588 to ad62222 Compare February 17, 2015 23:08
*/
public function __construct(DefaultSettingsProviderInterface $defaultSettingsProvider)
public function setDefaultSettingsProvider(DefaultSettingsProviderInterface $defaultSettingsProvider)
Copy link
Member

Choose a reason for hiding this comment

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

Why changing it to setter injection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the recommended way for abstract service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amenophis
Copy link
Contributor Author

@pjedrzejewski got an idea about decoupling render and sender. will try to add it tonight.

@amenophis
Copy link
Contributor Author

@pjedrzejewski also see that renderBlock could not be called as it is not in the interface. what do you think ?

@amenophis
Copy link
Contributor Author

@pjedrzejewski I introduce Renderer and Sender separation. What do you think about it ?

/**
* @author Jérémy Leherpeur <jeremy@leherpeur.net>
*/
abstract class AbstractAdapter
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is totally useless...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes for the moment. Maybe i will inject the event_dispatcher.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !

@amenophis amenophis force-pushed the mailer-event branch 4 times, most recently from d6e6052 to 2659182 Compare February 22, 2015 10:48
@amenophis amenophis changed the title Dispatch Event after email sent Dispatch Event after email sent + split Sender and Renderer Feb 22, 2015
@pjedrzejewski
Copy link
Member

Sounds cool, I will take a look at the code soonish.

@amenophis
Copy link
Contributor Author

OK nice ! wait for your review !

/**
* @author Jérémy Leherpeur <jeremy@leherpeur.net>
*/
class EmailRenderedEvent extends Event
Copy link
Contributor

Choose a reason for hiding this comment

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

Why having two event classes that holds almost same data instead of one, and some optional parameter while using "recipients"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ! Just merge the two in one Event class

@stloyd
Copy link
Contributor

stloyd commented Feb 23, 2015

You should fix CS & rebase code.

@amenophis amenophis force-pushed the mailer-event branch 3 times, most recently from 27f6561 to 6fb3d09 Compare February 23, 2015 10:41
<service id="sylius.email_sender.adapter.twig_swiftmailer" class="%sylius.email_sender.adapter.twig_swiftmailer.class%">
<argument type="service" id="sylius.mailer.default_settings_provider" />
<argument type="service" id="mailer" />
<service id="sylius.email_renderer.adapter.abstract" class="%sylius.email_renderer.adapter.abstract.class%" abstract="true">
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that all those new services should be public as they will be only used internally by Sender class...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be used by another bundle to create a new adapter

@amenophis
Copy link
Contributor Author

Fixed, Rebased and squashed.
@pjedrzejewski It's up to you now ;)

@stloyd
Copy link
Contributor

stloyd commented Mar 4, 2015

@pjedrzejewski 👍

@stloyd
Copy link
Contributor

stloyd commented Mar 11, 2015

@pjedrzejewski ping ;)

@amenophis
Copy link
Contributor Author

@stloyd thanks for pinging :)
@pjedrzejewski ping 😃

@pjedrzejewski
Copy link
Member

@amenophis I will try to review it today, sorry!

/** @var EmailEvent $event */
$event = $this->dispatcher->dispatch(self::EVENT_EMAIL_RENDERED, new EmailEvent($subject, $body));

return array(
Copy link
Member

Choose a reason for hiding this comment

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

I believe we should introduce an object here, not array, like "RenderedEmail" class.

@pjedrzejewski
Copy link
Member

Looks cool, please apply my comments if you agree and I will be happy to merge it. :) Please remember to add event dispatcher to the deps!

@amenophis
Copy link
Contributor Author

OK, will add it ASAP.
Thanks for review !

@amenophis
Copy link
Contributor Author

@pjedrzejewski done.
I didn't add dispatcher to the deps because already require "symfony/framework-bundle"

OK ?

@amenophis
Copy link
Contributor Author

@stloyd @pjedrzejewski I'm not really expert with phpSpec, could you help with the fix for Specs ?


$adapter->send($email, array('jonh@example.com'), array('foo' => 2))->shouldBeCalled();
$rendererAdapter->render($email, array('foo' => 2))->shouldBeCalled();
$senderAdapter->send(array('jonh@example.com'), null, null, null)->shouldBeCalled();

$this->send('bar', array('jonh@example.com'), array('foo' => 2));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be:

    function it_sends_an_email_through_the_adapter(
        $rendererAdapter,
        $senderAdapter,
        $provider,
        EmailInterface $email,
        RenderedEmail $renderedEmail
    ) {
        $provider->getEmail('bar')->shouldBeCalled()->willReturn($email);
        $email->isEnabled()->shouldBeCalled()->willReturn(true);
        $email->getSenderAddress()->shouldBeCalled();
        $email->getSenderName()->shouldBeCalled();

        $rendererAdapter->render($email, array('foo' => 2))->willReturn($renderedEmail);
        $senderAdapter->send(array('jonh@example.com'), null, null, $renderedEmail)->shouldBeCalled();

        $this->send('bar', array('jonh@example.com'), array('foo' => 2));
    }

@amenophis amenophis force-pushed the mailer-event branch 2 times, most recently from c6efaed to f6aba81 Compare March 18, 2015 12:42
Introduce Email Renderer
@amenophis
Copy link
Contributor Author

@stloyd done
Thanks for specs, works locally

@pjedrzejewski Time to merge ?

@amenophis
Copy link
Contributor Author

@pjedrzejewski ?

@stloyd
Copy link
Contributor

stloyd commented Mar 24, 2015

@pjedrzejewski Is there anything blocking this? Review was done few times already...

pjedrzejewski pushed a commit that referenced this pull request Mar 25, 2015
Dispatch Event after email sent + split Sender and Renderer
@pjedrzejewski pjedrzejewski merged commit 99c611d into Sylius:master Mar 25, 2015
@pjedrzejewski
Copy link
Member

Thank you Jeremy! 👍 Great work.

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

3 participants