Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created January 25, 2015 14:15
Show Gist options
  • Save amacgregor/85108283f3ca51156bdd to your computer and use it in GitHub Desktop.
Save amacgregor/85108283f3ca51156bdd to your computer and use it in GitHub Desktop.
<?php
interface NotificationInterface {
public function setData($data);
public function sendNotification();
}
class TwitterAdapter implements NotificationInterface
{
protected $_data;
public function setData($data){
$this->_data = $data;
}
public function sendNotification()
{
$twitterClient = new TwitterService();
$twitterClient->setMessage($this->_data['message']);
$twitterClient->sendTweet();
}
}
class EmailAdapter implements NotificationInterface
{
protected $_data;
public function setData($data){
$this->_data = $data;
}
public function sendNotification()
{
$emailClient = new EmailService();
$emailClient->setTitle($this->_data['title']);
$emailClient->setMessage($this->_data['message']);
$emailClient->setFrom($this->_data['from']);
$emailClient->setTo($this->_data['to']);
$emailClient->sendEmail();
}
}
class SmsAdapter implements NotificationInterface
{
protected $_data;
public function setData($data){
$this->_data = $data;
}
public function sendNotification()
{
$smsClient = new SmsService();
$smsClient->setRecipient($this->_data['recipient']);
$smsClient->setMessage($this->_data['message']);
$smsClient->sendText();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment