Skip to content

Instantly share code, notes, and snippets.

@avosalmon
Last active May 7, 2019 12:57
Show Gist options
  • Save avosalmon/11d7c2a2d1796083407ebe8fa11c8a11 to your computer and use it in GitHub Desktop.
Save avosalmon/11d7c2a2d1796083407ebe8fa11c8a11 to your computer and use it in GitHub Desktop.
<?php
interface OrderNotificationInterface
{
public function notify(Order $order) : void;
}
class SlackNotification implements OrderNotificationInterface
{
public function __construct(Slack $slack) {
$this->slack = $slack;
}
public function notify(Order $order) : void
{
$message = $this->getMessage($order);
$this->slack->to('#order')->send($message);
}
protected function getMessage(Order $order) : string
{
$format = '@%s Order has been processed. OrderID: %d';
$userName = $order->getUserName();
$message = sprintf($format, $userName, $order->getId());
return $message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment