Last active
April 9, 2021 11:52
-
-
Save shivapoudel/b623466f005b97945db76678dff08ee0 to your computer and use it in GitHub Desktop.
Learning some PHP use cases!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Logger { | |
public function log( $message ) { | |
return "LOG : {$message}" . PHP_EOL; | |
} | |
} | |
interface MailSentAction { | |
public function sent( $message ); | |
} | |
abstract class Mail implements MailSentAction{ | |
private $logger; | |
public function __construct( Logger $logger ) { | |
$this->logger = $logger; | |
} | |
public function log( $message ) { | |
return $this->logger->log( $message ); | |
} | |
public function sent( $message ) { | |
return $message; | |
} | |
} | |
class GoogleMail extends Mail { | |
public function send( $message ) { | |
return "GoogleMail: {$message}" . PHP_EOL; | |
} | |
} | |
class MailgunMail extends Mail{ | |
public function send( $message ) { | |
return "MailgunMail: {$message}" . PHP_EOL; | |
} | |
} | |
class UserManager { | |
private $mail; | |
public function __construct( MailSentAction $mail ) { | |
$this->mail = $mail; | |
} | |
public function send( $message ) { | |
echo $this->mail->send( $message ); | |
} | |
public function log( $message ) { | |
echo $this->mail->log( $message ); | |
} | |
} | |
$user_manager = new UserManager(); | |
$user_manager->send( 'Hello Test' ); | |
$user_manager->log( 'Log Test' ); | |
$user_manager = new UserManager(); | |
$user_manager->send( 'Hello Test' ); | |
$user_manager->log( 'Log Test' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment