Created
January 25, 2015 14:15
-
-
Save amacgregor/85108283f3ca51156bdd to your computer and use it in GitHub Desktop.
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 | |
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