Skip to content

Commit 96f6aa5

Browse files
committed
Fix header(replace) default value
1 parent 839f9e8 commit 96f6aa5

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,85 @@
11
<?php
2-
32
namespace Ubiquity\utils\http\foundation;
43

54
/**
65
* Http instance for ReactPHP.
76
* Ubiquity\utils\http\foundation$ReactHttp
87
* This class is part of Ubiquity
8+
*
99
* @author jcheron <myaddressmail@gmail.com>
1010
* @version 1.0.0
11-
*
11+
*
1212
*/
1313
class ReactHttp extends AbstractHttp {
14+
1415
private $headers;
15-
private $responseCode=200;
16+
17+
private $responseCode = 200;
18+
1619
private $request;
17-
18-
20+
1921
public function getAllHeaders() {
2022
return $this->headers;
2123
}
2224

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;
2729
}
2830
}
29-
31+
3032
/**
33+
*
3134
* @return int
3235
*/
3336
public function getResponseCode() {
3437
return $this->responseCode;
3538
}
3639

3740
/**
41+
*
3842
* @param mixed $headers
3943
*/
4044
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) {
4347
$this->headers[$k] = current($header);
44-
}else{
45-
$this->headers[$k]=$header;
48+
} else {
49+
$this->headers[$k] = $header;
4650
}
4751
}
4852
}
4953

5054
/**
55+
*
5156
* @param int $responseCode
5257
*/
5358
public function setResponseCode($responseCode) {
54-
if($responseCode!=null){
59+
if ($responseCode != null) {
5560
$this->responseCode = $responseCode;
5661
}
5762
}
58-
63+
5964
public function headersSent(string &$file = null, int &$line = null) {
6065
return false;
6166
}
62-
67+
6368
public function getInput() {
6469
return $this->request->getParsedBody();
6570
}
71+
6672
/**
73+
*
6774
* @param mixed $request
6875
*/
6976
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()));
7383
}
7484
}
7585

0 commit comments

Comments
 (0)