1 | <?php |
||
30 | class Dispatcher implements LoggerAwareInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $connectionPool; |
||
36 | |||
37 | /** |
||
38 | * @var ServiceClientFactory |
||
39 | */ |
||
40 | private $clientFactory; |
||
41 | |||
42 | /** |
||
43 | * @var NotificationBuilder |
||
44 | */ |
||
45 | private $notificationBuilder; |
||
46 | |||
47 | /** |
||
48 | * @var ResponseHandler |
||
49 | */ |
||
50 | private $responseHandler; |
||
51 | |||
52 | /** |
||
53 | * @var LoggerInterface |
||
54 | */ |
||
55 | private $logger; |
||
56 | |||
57 | /** |
||
58 | * @param ServiceClientFactory $clientFactory |
||
59 | * @param NotificationBuilder $notificationBuilder |
||
60 | * @param ResponseHandler $responseHandler |
||
61 | */ |
||
62 | public function __construct( |
||
63 | ServiceClientFactory $clientFactory, |
||
64 | NotificationBuilder $notificationBuilder, |
||
65 | ResponseHandler $responseHandler |
||
66 | ){ |
||
67 | $this->clientFactory = $clientFactory; |
||
68 | $this->notificationBuilder = $notificationBuilder; |
||
69 | $this->responseHandler = $responseHandler; |
||
70 | |||
71 | $this->setLogger(new NullLogger()); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param LoggerInterface $logger |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function setLogger(LoggerInterface $logger) |
||
83 | |||
84 | /** |
||
85 | * @param bool $isDevelopment |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function setDevelopmentMode($isDevelopment) |
||
93 | |||
94 | /** |
||
95 | * Gets a service client connection by service name |
||
96 | * |
||
97 | * @param string $serviceName |
||
98 | * @return ServiceClientInterface |
||
99 | */ |
||
100 | public function getConnection($serviceName) |
||
108 | |||
109 | /** |
||
110 | * Initialize service client connection by service name |
||
111 | * |
||
112 | * @param string $serviceName |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function initConnection($serviceName) |
||
122 | |||
123 | /** |
||
124 | * Creates a feedback service connection |
||
125 | * |
||
126 | * @param string $serviceName |
||
127 | * @return ServiceClientInterface |
||
128 | */ |
||
129 | public function initFeedbackConnection($serviceName) |
||
133 | |||
134 | /** |
||
135 | * @return ResponseHandler |
||
136 | */ |
||
137 | public function getResponseHandler() |
||
141 | |||
142 | /** |
||
143 | * Build notification and send it to notification service |
||
144 | * |
||
145 | * @param MessageInterface $message |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function dispatch(MessageInterface $message) |
||
163 | |||
164 | /** |
||
165 | * Tries to dispatch all messages to notification service |
||
166 | * |
||
167 | * @param MessageCollection $messages |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function dispatchAll(MessageCollection $messages) |
||
182 | |||
183 | /** |
||
184 | * Tries to connect and send a notification |
||
185 | * |
||
186 | * @param Notification $notification |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function sendNotification(Notification $notification) |
||
229 | |||
230 | /** |
||
231 | * Tries to connect and load feedback data |
||
232 | * |
||
233 | * @return $this |
||
234 | * @throws RuntimeException |
||
235 | * @throws \Exception |
||
236 | */ |
||
237 | public function loadFeedback() |
||
265 | } |
||
266 |