Advertisement
shaejah6

Untitled

Aug 10th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. interface EmailServiceInterface {
  3. }
  4.  
  5. class PepipostEmailService extends EmailServiceInterface {
  6. }
  7.  
  8. class MailgunEmailService extends EmailServiceInterface {
  9. }
  10.  
  11.  
  12. class EmailServiceFactory {
  13.     public static function create(string $serviceName): EmailServiceInterface {
  14.         switch ($serviceName) {
  15.             case 'pepipost':
  16.                 return new PepipostEmailService();
  17.  
  18.             case 'mailgun':
  19.                 return MailgunEmailService();
  20.  
  21.             default:
  22.                 return new PepipostEmailService();
  23.         }
  24.     }
  25. }
  26.  
  27. // Su dung
  28. $emailService = EmailServiceFactory::create(config('email_service.service_name'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement