Masterchoc

Untitled

Aug 9th, 2019
199
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class MailerAdapter
  4. {
  5.     private $transport;
  6.  
  7.     public function __construct($name = 'Mailgun')
  8.     {
  9.         $this->setTransport($name);
  10.     }
  11.  
  12.     public function setTransport($name)
  13.     {
  14.         $this->transport = new ($name . 'Transport');
  15.     }
  16.  
  17.     public function send($email)
  18.     {
  19.         $this->transport->send($email);
  20.     }
  21. }
  22.  
  23. class MailgunTransport extends MailerAdapter
  24. {
  25.     private $mailgun_api;
  26.  
  27.     public function __construct()
  28.     {
  29.         $this->mailgun_api = Mailgun::create($_ENV['MAILGUN_KEY']);
  30.     }
  31.  
  32.     public function send($email)
  33.     {
  34.         $this->mailgun_api->send($email);
  35.     }
  36. }
  37.  
  38.  
  39. class MailjetTransport extends MailerAdapter
  40. {
  41.     private $mailjet_api;
  42.  
  43.     public function __construct()
  44.     {
  45.         $this->mailjet_api = new mailjet();
  46.     }
  47.  
  48.     public function send($email)
  49.     {
  50.         $this->mailjet_api->send($email);
  51.     }
  52. }
  53.  
  54. $mailer = new MailerAdapter();
  55. $mailer->setTransport('Mailgun');
  56. $mailer->send('mon email');
RAW Paste Data