1
|
|
|
<?php |
2
|
|
|
namespace DevOp\Core\Http\Traits; |
3
|
|
|
|
4
|
|
|
use Psr\Http\Message\StreamInterface; |
5
|
|
|
|
6
|
|
|
trait MessageTrait |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var StreamInterface |
11
|
|
|
*/ |
12
|
|
|
private $body; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
private $headers = []; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private $headersName = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $protocolVersion = 1.1; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var StreamInterface |
31
|
|
|
*/ |
32
|
|
|
private $stream; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return Stream |
|
|
|
|
36
|
|
|
*/ |
37
|
2 |
|
public function getBody() |
38
|
|
|
{ |
39
|
2 |
|
return $this->body; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param StreamInterface $body |
44
|
|
|
* @return \DevOp\Core\Http\MessageTrait|$this |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function withBody(StreamInterface $body) |
47
|
|
|
{ |
48
|
|
|
if ($body === $this->stream) { |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$clone = clone $this; |
53
|
|
|
$clone->stream = $body; |
54
|
|
|
|
55
|
|
|
return $clone; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $name |
60
|
|
|
* @return boolean |
61
|
|
|
*/ |
62
|
|
|
public function hasHeader($name) |
63
|
|
|
{ |
64
|
|
|
return isset($this->headersName[strtolower($name)]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $name |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function getHeader($name) |
72
|
|
|
{ |
73
|
|
|
if ($this->hasHeader($name)) { |
74
|
|
|
return [$this->headers[$this->headersName[strtolower($name)]]]; |
75
|
|
|
} |
76
|
|
|
return []; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getHeaderLine($name) |
80
|
|
|
{ |
81
|
|
|
return implode(', ', $this->getHeader($name)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return array) |
86
|
|
|
*/ |
87
|
|
|
public function getHeaders() |
88
|
|
|
{ |
89
|
|
|
return $this->headers; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $name |
94
|
|
|
* @param mixed $value |
95
|
|
|
* @return self |
96
|
|
|
*/ |
97
|
|
|
public function withHeader($name, $value) |
98
|
|
|
{ |
99
|
|
|
$clone = new $this; |
100
|
|
|
|
101
|
|
|
$normalize = strtolower($name); |
102
|
|
|
|
103
|
|
|
if ($clone->hasHeader($name)) { |
104
|
|
|
unset($clone->headers[$this->headersName[$normalize]]); |
105
|
|
|
unset($clone->headersName[$normalize]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$clone->headersName[$normalize] = $name; |
109
|
|
|
$clone->headers[$normalize] = is_array($value) ? $value : [$value]; |
110
|
|
|
|
111
|
|
|
return $clone; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function withAddedHeader($name, $value) |
115
|
|
|
{ |
116
|
|
|
$clone = new $this; |
117
|
|
|
|
118
|
|
|
$normalize = strtolower($name); |
119
|
|
|
|
120
|
|
|
if ($clone->hasHeader($name)) { |
121
|
|
|
$clone->headers[$normalize] = array_merge($this->headers, is_array($value) ? $value : [$value]); |
122
|
|
|
} else { |
123
|
|
|
$clone->headersName[$normalize] = $name; |
124
|
|
|
$clone->headers[$normalize] = is_array($value) ? $value : [$value]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $clone; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $name |
132
|
|
|
* @return self |
133
|
|
|
*/ |
134
|
|
|
public function withoutHeader($name) |
135
|
|
|
{ |
136
|
|
|
$clone = new $this; |
137
|
|
|
|
138
|
|
|
$normalize = strtolower($name); |
139
|
|
|
|
140
|
|
|
if ($clone->hasHeader($name)) { |
141
|
|
|
unset($clone->headers[$this->headersName[$normalize]]); |
142
|
|
|
unset($clone->headersName[$normalize]); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $clone; |
146
|
|
|
} |
147
|
|
|
|
148
|
4 |
|
public function getProtocolVersion() |
149
|
|
|
{ |
150
|
4 |
|
return $this->protocolVersion; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $version |
155
|
|
|
* @return \DevOp\Core\Http\Message|$this |
|
|
|
|
156
|
|
|
*/ |
157
|
2 |
|
public function withProtocolVersion($version) |
158
|
|
|
{ |
159
|
2 |
|
if ($version === $this->protocolVersion) { |
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
2 |
|
$clone = clone $this; |
164
|
2 |
|
$clone->protocolVersion = $version; |
165
|
|
|
|
166
|
2 |
|
return $clone; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths