1 <?php
2 /* --------------------------------------------------------------
3 HttpResponseProcessor.inc.php 2015-03-12 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('HttpResponseProcessorInterface');
13
14 /**
15 * Class HttpResponseProcessor
16 *
17 * @category System
18 * @package Http
19 * @implements HttpResponseProcessorInterface
20 */
21 class HttpResponseProcessor implements HttpResponseProcessorInterface
22 {
23 /**
24 * Processes the http response object which is returned by a controller action method.
25 * Sends the processed response header and body to the client (Either redirect or display some output).
26 *
27 * @param HttpControllerResponseInterface $response Response object from the controllers action method.
28 */
29 public function proceed(HttpControllerResponseInterface $response)
30 {
31 $this->_sendHeaders($response->getHeaders());
32 $this->_sendBody($response->getBody());
33 }
34
35
36 /**
37 * Sends the response header data to the client by the given http headers array.
38 *
39 * @see header Function to send headers data.
40 *
41 * @param array $httpHeadersArrays Array which contains the header items.
42 */
43 protected function _sendHeaders(array $httpHeadersArrays)
44 {
45 foreach($httpHeadersArrays as $headerItem)
46 {
47 header($headerItem);
48 }
49 }
50
51
52 /**
53 * Sends the response body data to the client.
54 *
55 * @param string $httpBody Rendered response body.
56 */
57 protected function _sendBody($httpBody)
58 {
59 echo $httpBody;
60 }
61 }