@@ -295,13 +295,15 @@ made. To do that, you create a new class::
295295 namespace App\Updates;
296296
297297 use App\Service\MessageGenerator;
298+ use Symfony\Component\Mailer\MailerInterface;
299+ use Symfony\Component\Mime\Email;
298300
299301 class SiteUpdateManager
300302 {
301303 private $messageGenerator;
302304 private $mailer;
303305
304- public function __construct(MessageGenerator $messageGenerator, \Swift_Mailer $mailer)
306+ public function __construct(MessageGenerator $messageGenerator, MailerInterface $mailer)
305307 {
306308 $this->messageGenerator = $messageGenerator;
307309 $this->mailer = $mailer;
@@ -311,19 +313,21 @@ made. To do that, you create a new class::
311313 {
312314 $happyMessage = $this->messageGenerator->getHappyMessage();
313315
314- $message = (new \Swift_Message('Site update just happened!'))
315- ->setFrom('admin@example.com')
316- ->setTo('manager@example.com')
317- ->addPart(
318- 'Someone just updated the site. We told them: '.$happyMessage
319- );
316+ $email = (new Email())
317+ ->from('admin@example.com')
318+ ->to('manager@example.com')
319+ ->subject('Site update just happened!')
320+ ->text('Someone just updated the site. We told them: '.$happyMessage);
320321
321- return $this->mailer->send($message) > 0;
322+ $this->mailer->send($email);
323+
324+ // ...
322325 }
323326 }
324327
325- This needs the ``MessageGenerator `` *and * the ``Swift_Mailer `` service. That's no
326- problem! In fact, this new service is ready to be used. In a controller, for example,
328+ This needs the ``MessageGenerator `` *and * the ``Mailer `` service. That's no
329+ problem, we ask them by type hinting their class and interface names!
330+ Now, this new service is ready to be used. In a controller, for example,
327331you can type-hint the new ``SiteUpdateManager `` class and use it::
328332
329333 // src/Controller/SiteController.php
0 commit comments