Last active
August 29, 2015 14:02
-
-
Save drgomesp/0e2d8bc0be9b32545b95 to your computer and use it in GitHub Desktop.
This file contains 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 | |
interface Mailer | |
{ | |
/** | |
* @throws CouldNotSendMailExeption | |
*/ | |
pubic function sendMail($to); | |
} | |
class CourierMailer implements Mailer | |
{ | |
public function sendMail($to) | |
{ | |
//... | |
if (filter_var($to, FILTER_EMAIL)) { | |
throw new InvalidArgumentException(); | |
} | |
} | |
} | |
class UserRegistrationListener | |
{ | |
private $mailer; | |
public function __construct(Mailer $mailer) | |
{ | |
$this->mailer = $mailer; | |
} | |
public function onRegister(User $user) | |
{ | |
try { | |
$this->mailer->sendMail($user->getEmail()); | |
} catch (CouldNotSendEmailException $e) { | |
// ... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment