| 1 | <?php |
||
| 10 | abstract class AbstractNotification implements PushNotificationInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var MessageQueue |
||
| 14 | */ |
||
| 15 | protected $messageQueue; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var Connection |
||
| 19 | */ |
||
| 20 | protected $stream; |
||
| 21 | |||
| 22 | 2 | public function __construct() |
|
| 23 | { |
||
| 24 | 2 | $this->messageQueue = new MessageQueue(); |
|
| 25 | 2 | } |
|
| 26 | |||
| 27 | abstract public function send(); |
||
| 28 | |||
| 29 | 1 | public function enqueue(MessageInterface $message) |
|
| 30 | { |
||
| 31 | 1 | $this->messageQueue->enqueue($message); |
|
| 32 | 1 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @param Connection $wrapper |
||
| 36 | */ |
||
| 37 | 1 | public function setStreamWrapper(Connection $wrapper) |
|
| 38 | { |
||
| 39 | 1 | $this->stream = $wrapper; |
|
| 40 | 1 | } |
|
| 41 | |||
| 42 | abstract protected function createPayload(MessageInterface $message); |
||
| 43 | |||
| 44 | 1 | final protected function openConnection() |
|
| 45 | { |
||
| 46 | 1 | $this->lazyInitStream(); |
|
| 47 | |||
| 48 | 1 | $this->stream->open($this->getConnectionParams(), null); |
|
| 49 | |||
| 50 | 1 | return $this; |
|
| 51 | } |
||
| 52 | |||
| 53 | 1 | private function lazyInitStream() |
|
| 54 | { |
||
| 55 | 1 | if ($this->stream === null) { |
|
| 56 | $this->stream = new CurlWrapper(); |
||
| 57 | } |
||
| 58 | 1 | } |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | abstract protected function getConnectionParams(); |
||
| 64 | } |