Skip to content

Instantly share code, notes, and snippets.

@drgomesp
Last active August 29, 2015 14:02
Show Gist options
  • Save drgomesp/0e2d8bc0be9b32545b95 to your computer and use it in GitHub Desktop.
Save drgomesp/0e2d8bc0be9b32545b95 to your computer and use it in GitHub Desktop.
<?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