Make "mailer" service optional#2801
Conversation
| * @param \Twig_Environment $twig | ||
| * @param array $parameters | ||
| */ | ||
| public function __construct($mailer, UrlGeneratorInterface $router, \Twig_Environment $twig, array $parameters) |
There was a problem hiding this comment.
$mailer Should be typed as \Swift_Mailer
There was a problem hiding this comment.
No it should not =) With a type hint it would not be possible to pass null value. Old TwigSwiftMailer had that type hint. I could not remove it from there because it would be BC break. So - i created a new class TwigMailer, a parent for old TwigSwiftMailer
There was a problem hiding this comment.
Ok, what's about
if(null !== $mailer && !($mailer instanceof \Swift_Mailer)
{
// throw ....
}?
Currently you can pass anything as $mailer... :D
There was a problem hiding this comment.
It turned out that there are more then one mailer! I found this out in @stof's comment last year in #2562 (comment) =) That is a reason why symfony/swiftmailer-bundle is not required dependency, btw. So, it is not necessary, i guess
There was a problem hiding this comment.
I think that there is no another mailer which uses the Swift_Message class (which comes from the swiftmailer package)
https://github.com/covex-nn/FOSUserBundle/blob/b3000d0088536a1384b7057aa0888a9caa42a45e/Mailer/TwigMailer.php#L115
There was a problem hiding this comment.
@devtronic actualy, i agree with you, and i am on your side! May be symfony/swiftmailer-bundle should be in require section of composer.json! Create a PR and i will be very glad if it will be accepted, then i will close this one =)
But, Swift_Message comes from swiftmailer/swiftmailer and it is not a bundle. So, it is possible to create a bundle, that provides mailer service and uses Swift_Message as a first argument of send method at the same time.
|
A travis job with |
With this PR the
mailerservice will not be required any more while compiling Container. Both mailers will throw exceptions on sending email ifmailerservice was not available.Also a compiler pass
CheckForMailerPass, introduced in #2639 was deprecated, and i created a new classTwigMailerwithout type hint in first argument of constructor. OldTwigSwiftMailerwas deprecated, i moved all properties and methods to a new class to avoid BC breaks.This PR with #2708 will make creating a recipe for Symfony Flex easier