1 | <?php |
||
27 | abstract class ReplyProducingMessageHandler extends \PEIP\ABS\Handler\MessageHandler |
||
28 | { |
||
29 | protected $outputChannel, |
||
30 | $messageClass = '\PEIP\Message\GenericMessage', |
||
31 | $replyChannelHeaders = ['REPLY_CHANNEL']; |
||
32 | |||
33 | /** |
||
34 | * Sets the output-channel for the message handler. |
||
35 | * Delegates connecting of input-channel to protected method 'doSetOutputChannel', |
||
36 | * which can be overwritten by extending classes. |
||
37 | * |
||
38 | * @see \PEIP\ABS\Handler\MessageHandler::doSetOutputChannel |
||
39 | * |
||
40 | * @param \PEIP\INF\Channel\Channel $outputChannel the output-channel |
||
41 | * |
||
42 | * @return \PEIP\ABS\Handler\MessageHandler $this; |
||
43 | */ |
||
44 | public function setOutputChannel(\PEIP\INF\Channel\Channel $outputChannel) |
||
50 | |||
51 | /** |
||
52 | * Connects the handler to the output-channel. |
||
53 | * |
||
54 | * @param \PEIP\INF\Channel\Channel $outputChannel the output-channel to connect the handler to |
||
55 | * |
||
56 | * @return |
||
57 | */ |
||
58 | protected function doSetOutputChannel(\PEIP\INF\Channel\Channel $outputChannel) |
||
62 | |||
63 | /** |
||
64 | * Returns the output-channel for this handler. |
||
65 | * |
||
66 | * @return \PEIP\INF\Channel\Channel output-channel for this handler |
||
67 | */ |
||
68 | public function getOutputChannel() |
||
72 | |||
73 | /** |
||
74 | * Resolves the output-channel for a message. |
||
75 | * Returns default output-channel if no reply-channel is found in |
||
76 | * the message headers. |
||
77 | * |
||
78 | * @see PEIP\ABS\Handler\ReplyProducingMessageHandler::resolveReplyChannel |
||
79 | * |
||
80 | * @param \PEIP\INF\Message\Message $message the message to resolve output-channel for |
||
81 | * |
||
82 | * @return \PEIP\INF\Channel\Channel the output-channel for the message |
||
83 | */ |
||
84 | protected function doGetOutputChannel(\PEIP\INF\Message\Message $message) |
||
90 | |||
91 | /** |
||
92 | * Resolves a reply-channel for a message. |
||
93 | * Looks for a reply-channel header in the message (default: 'REPLY_CHANNEL') |
||
94 | * and returns it�s value, if found. |
||
95 | * |
||
96 | * @param \PEIP\INF\Message\Message $message |
||
97 | * |
||
98 | * @return \PEIP\INF\Channel\Channel the reply-channel if found |
||
99 | */ |
||
100 | protected function resolveReplyChannel(\PEIP\INF\Message\Message $message) |
||
108 | |||
109 | /** |
||
110 | * Sends a reply-message on a appropriate channel. |
||
111 | * Argument $content can be either a message (\PEIP\INF\Message\Message) or |
||
112 | * the content/payload to create a new message for. |
||
113 | * |
||
114 | * @see PEIP\ABS\Handler\ReplyProducingMessageHandler::ensureMessage |
||
115 | * @see PEIP\ABS\Handler\ReplyProducingMessageHandler::doGetOutputChannel |
||
116 | * |
||
117 | * @param mixed $content \PEIP\INF\Message\Message or content/payload for new message |
||
118 | */ |
||
119 | protected function replyMessage($content) |
||
124 | |||
125 | /** |
||
126 | * Ensures to return a valid \PEIP\INF\Message\Message instance. |
||
127 | * If argument $message is not instance of \PEIP\INF\Message\Message, creates |
||
128 | * a new message with $message as content/payload. |
||
129 | * |
||
130 | * @param mixed $message \PEIP\INF\Message\Message or content/payload for new message |
||
131 | * |
||
132 | * @return \PEIP\INF\Message\Message |
||
133 | */ |
||
134 | protected function ensureMessage($message) |
||
138 | |||
139 | /** |
||
140 | * Creates a new message instance with given content as content/payload. |
||
141 | * Delegates creation of message to instance of MessageBuilder. |
||
142 | * |
||
143 | * @param mixed $content content/payload for the message |
||
144 | * |
||
145 | * @return \PEIP\INF\Message\Message |
||
146 | * |
||
147 | * @see MessageBuilder |
||
148 | */ |
||
149 | protected function buildMessage($content) |
||
153 | |||
154 | /** |
||
155 | * Returns the a instance of MessageBuilder for the registered message class |
||
156 | * to create reply-messages from. |
||
157 | * |
||
158 | * @return MessageBuilder builder for the registered message class |
||
159 | */ |
||
160 | protected function getMessageBuilder() |
||
166 | |||
167 | /** |
||
168 | * Sets the message-class to create reply-messages from. |
||
169 | * |
||
170 | * @param string $messageClass name of the message-class to create reply-messages from. |
||
171 | * |
||
172 | * @return ReplyProducingMessageHandler $this |
||
173 | */ |
||
174 | public function setMessageClass($messageClass) |
||
180 | |||
181 | /** |
||
182 | * Returns the message-class to create reply-messages from. |
||
183 | * |
||
184 | * @return string name of the message-class to create reply-messages from. |
||
185 | */ |
||
186 | public function getMessageClass() |
||
190 | |||
191 | /** |
||
192 | * Adds the name of a message-header to look for a reply-channel. |
||
193 | * |
||
194 | * @param string $headerName name of a message-header to look for a reply-channel |
||
195 | * |
||
196 | * @return void |
||
197 | */ |
||
198 | public function addReplyChannelHeader($headerName) |
||
202 | |||
203 | /** |
||
204 | * Sets all message-header names to look for a reply-channel. |
||
205 | * |
||
206 | * @param array $headerNames array of message-header names to look for a reply-channel |
||
207 | * |
||
208 | * @return ReplyProducingMessageHandler $this |
||
209 | */ |
||
210 | public function setReplyChannelHeaders(array $headerNames) |
||
216 | |||
217 | /** |
||
218 | * Returns all message-header names to look for a reply-channel. |
||
219 | * |
||
220 | * @return array array of message-header names to look for a reply-channel |
||
221 | */ |
||
222 | public function getReplyChannelHeaders() |
||
226 | |||
227 | /** |
||
228 | * Does the message handling logic for the handler. |
||
229 | * Implements abstract method of \PEIP\ABS\Handler\MessageHandler. |
||
230 | * Delegates the handling of the message to abstract 'doReply' |
||
231 | * method which must be implemented by extending classes. |
||
232 | * |
||
233 | * @param \PEIP\INF\Message\Message $message |
||
234 | * |
||
235 | * @return |
||
236 | */ |
||
237 | protected function doHandle(\PEIP\INF\Message\Message $message) |
||
241 | |||
242 | /** |
||
243 | * Does the message replying logic for the handler. |
||
244 | * Must be implemented by extending classes. |
||
245 | * |
||
246 | * @abstract |
||
247 | * |
||
248 | * @param \PEIP\INF\Message\Message $message the message to reply with |
||
249 | */ |
||
250 | abstract protected function doReply(\PEIP\INF\Message\Message $message); |
||
251 | } |
||
252 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: