1 | <?php |
||
11 | abstract class AbstractNotification implements PushNotificationInterface, LifeCycleCallback |
||
12 | { |
||
13 | /** |
||
14 | * @var MessageQueue |
||
15 | */ |
||
16 | protected $messageQueue; |
||
17 | |||
18 | /** |
||
19 | * @var Connection |
||
20 | */ |
||
21 | protected $stream; |
||
22 | |||
23 | /** |
||
24 | * @var CallbackInvoker |
||
25 | */ |
||
26 | protected $invoker; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $retryCount = 1; |
||
32 | |||
33 | /** |
||
34 | * AbstractNotification constructor. |
||
35 | */ |
||
36 | 20 | public function __construct() |
|
41 | |||
42 | 8 | final public function send() |
|
65 | |||
66 | abstract protected function sendImpl(MessageInterface $message); |
||
67 | |||
68 | 6 | public function enqueue(MessageInterface $message) |
|
72 | |||
73 | /** |
||
74 | * @param Connection $wrapper |
||
75 | */ |
||
76 | 9 | public function setStreamWrapper(Connection $wrapper) |
|
80 | |||
81 | /** |
||
82 | * @param int $count |
||
83 | */ |
||
84 | 10 | public function setRetryCount($count) |
|
91 | |||
92 | abstract protected function createPayload(MessageInterface $message); |
||
93 | |||
94 | 6 | final protected function openConnection() |
|
102 | |||
103 | 6 | protected function notifyOnComplete(MessageQueue $messages) |
|
107 | |||
108 | 5 | protected function notifyOnEachSent(MessageInterface $message, $feedBack) |
|
112 | |||
113 | protected function notifyOnError(MessageInterface $message, PushNotificationException $exc) |
||
117 | |||
118 | 2 | public function onComplete(\Closure $listener) |
|
122 | |||
123 | 4 | public function onEachSent(\Closure $callback) |
|
127 | |||
128 | public function onError(\Closure $callback) |
||
132 | |||
133 | 2 | public function detach() |
|
137 | |||
138 | 6 | private function lazyInitStream() |
|
144 | |||
145 | /** |
||
146 | * @return array |
||
147 | */ |
||
148 | abstract protected function getConnectionParams(); |
||
149 | } |