Masterchoc

Untitled

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