|
1 | 1 | <?php |
2 | | - |
3 | 2 | namespace Ubiquity\utils\http\foundation; |
4 | 3 |
|
5 | 4 | /** |
6 | 5 | * Http instance for ReactPHP. |
7 | 6 | * Ubiquity\utils\http\foundation$ReactHttp |
8 | 7 | * This class is part of Ubiquity |
| 8 | + * |
9 | 9 | * @author jcheron <myaddressmail@gmail.com> |
10 | 10 | * @version 1.0.0 |
11 | | - * |
| 11 | + * |
12 | 12 | */ |
13 | 13 | class ReactHttp extends AbstractHttp { |
| 14 | + |
14 | 15 | private $headers; |
15 | | - private $responseCode=200; |
| 16 | + |
| 17 | + private $responseCode = 200; |
| 18 | + |
16 | 19 | private $request; |
17 | | - |
18 | | - |
| 20 | + |
19 | 21 | public function getAllHeaders() { |
20 | 22 | return $this->headers; |
21 | 23 | } |
22 | 24 |
|
23 | | - public function header($key,$value,$replace=null,$http_response_code=null) { |
24 | | - $this->headers[$key]=$value; |
25 | | - if($http_response_code!=null){ |
26 | | - $this->responseCode=$http_response_code; |
| 25 | + public function header($key, $value, bool $replace = true, int $http_response_code = null) { |
| 26 | + $this->headers[$key] = $value; |
| 27 | + if ($http_response_code != null) { |
| 28 | + $this->responseCode = $http_response_code; |
27 | 29 | } |
28 | 30 | } |
29 | | - |
| 31 | + |
30 | 32 | /** |
| 33 | + * |
31 | 34 | * @return int |
32 | 35 | */ |
33 | 36 | public function getResponseCode() { |
34 | 37 | return $this->responseCode; |
35 | 38 | } |
36 | 39 |
|
37 | 40 | /** |
| 41 | + * |
38 | 42 | * @param mixed $headers |
39 | 43 | */ |
40 | 44 | private function setHeaders($headers) { |
41 | | - foreach ($headers as $k=>$header){ |
42 | | - if(is_array($header) && sizeof($header)==1){ |
| 45 | + foreach ($headers as $k => $header) { |
| 46 | + if (is_array($header) && sizeof($header) == 1) { |
43 | 47 | $this->headers[$k] = current($header); |
44 | | - }else{ |
45 | | - $this->headers[$k]=$header; |
| 48 | + } else { |
| 49 | + $this->headers[$k] = $header; |
46 | 50 | } |
47 | 51 | } |
48 | 52 | } |
49 | 53 |
|
50 | 54 | /** |
| 55 | + * |
51 | 56 | * @param int $responseCode |
52 | 57 | */ |
53 | 58 | public function setResponseCode($responseCode) { |
54 | | - if($responseCode!=null){ |
| 59 | + if ($responseCode != null) { |
55 | 60 | $this->responseCode = $responseCode; |
56 | 61 | } |
57 | 62 | } |
58 | | - |
| 63 | + |
59 | 64 | public function headersSent(string &$file = null, int &$line = null) { |
60 | 65 | return false; |
61 | 66 | } |
62 | | - |
| 67 | + |
63 | 68 | public function getInput() { |
64 | 69 | return $this->request->getParsedBody(); |
65 | 70 | } |
| 71 | + |
66 | 72 | /** |
| 73 | + * |
67 | 74 | * @param mixed $request |
68 | 75 | */ |
69 | 76 | public function setRequest($request) { |
70 | | - $this->request=$request; |
71 | | - $default=['Content-Type'=>'text/html; charset=utf-8','Server'=>$request->getUri()->getHost()]; |
72 | | - $this->setHeaders(array_merge($default,$request->getHeaders())); |
| 77 | + $this->request = $request; |
| 78 | + $default = [ |
| 79 | + 'Content-Type' => 'text/html; charset=utf-8', |
| 80 | + 'Server' => $request->getUri()->getHost() |
| 81 | + ]; |
| 82 | + $this->setHeaders(array_merge($default, $request->getHeaders())); |
73 | 83 | } |
74 | 84 | } |
75 | 85 |
|
0 commit comments