1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
7
|
|
|
use Psr\Http\Message\StreamFactoryInterface; |
8
|
|
|
use Psr\Http\Message\StreamInterface; |
9
|
|
|
|
10
|
|
|
class DeferredResponse implements ResponseInterface |
11
|
|
|
{ |
12
|
|
|
private ResponseInterface $response; |
13
|
|
|
|
14
|
|
|
private StreamFactoryInterface $streamFactory; |
15
|
|
|
|
16
|
|
|
private $data; |
17
|
|
|
|
18
|
|
|
private ?StreamInterface $dataStream = null; |
19
|
|
|
|
20
|
|
|
private ?ResponseFormatterInterface $responseFormatter = null; |
21
|
|
|
|
22
|
|
|
public function __construct($data, ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory) |
23
|
|
|
{ |
24
|
|
|
$this->response = $responseFactory->createResponse(); |
25
|
|
|
$this->streamFactory = $streamFactory; |
26
|
|
|
$this->data = $data; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getBody() |
30
|
|
|
{ |
31
|
|
|
if ($this->dataStream !== null) { |
32
|
|
|
return $this->dataStream; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$data = $this->getData(); |
36
|
|
|
|
37
|
|
|
if ($this->responseFormatter !== null) { |
38
|
|
|
$this->response = $this->formatResponse(); |
39
|
|
|
return $this->dataStream = $this->response->getBody(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (is_string($data)) { |
43
|
|
|
return $this->dataStream = $this->streamFactory->createStream($data); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
throw new \RuntimeException('Data must be a string value.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getHeader($name) |
50
|
|
|
{ |
51
|
|
|
return $this->response->getHeader($name); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getHeaderLine($name) |
55
|
|
|
{ |
56
|
|
|
return $this->response->getHeaderLine($name); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getHeaders() |
60
|
|
|
{ |
61
|
|
|
return $this->response->getHeaders(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getProtocolVersion() |
65
|
|
|
{ |
66
|
|
|
return $this->response->getProtocolVersion(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getReasonPhrase() |
70
|
|
|
{ |
71
|
|
|
return $this->response->getReasonPhrase(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getStatusCode() |
75
|
|
|
{ |
76
|
|
|
return $this->response->getStatusCode(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function hasHeader($name) |
80
|
|
|
{ |
81
|
|
|
return $this->response->hasHeader($name); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function withAddedHeader($name, $value) |
85
|
|
|
{ |
86
|
|
|
$response = clone $this; |
87
|
|
|
$response->response = $this->response->withAddedHeader($name, $value); |
88
|
|
|
return $response; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function withBody(StreamInterface $body) |
92
|
|
|
{ |
93
|
|
|
$response = clone $this; |
94
|
|
|
$response->dataStream = $body; |
95
|
|
|
return $response; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function withHeader($name, $value) |
99
|
|
|
{ |
100
|
|
|
$response = clone $this; |
101
|
|
|
$response->response = $this->response->withHeader($name, $value); |
102
|
|
|
return $response; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function withoutHeader($name) |
106
|
|
|
{ |
107
|
|
|
$response = clone $this; |
108
|
|
|
$response->response = $this->response->withoutHeader($name); |
109
|
|
|
return $response; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function withProtocolVersion($version) |
113
|
|
|
{ |
114
|
|
|
$response = clone $this; |
115
|
|
|
$response->response = $this->response->withProtocolVersion($version); |
116
|
|
|
return $response; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function withStatus($code, $reasonPhrase = '') |
120
|
|
|
{ |
121
|
|
|
$response = clone $this; |
122
|
|
|
$response->response = $this->response->withStatus($code, $reasonPhrase); |
123
|
|
|
return $response; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function withResponseFormatter(ResponseFormatterInterface $responseFormatter) |
127
|
|
|
{ |
128
|
|
|
$response = clone $this; |
129
|
|
|
$response->responseFormatter = $responseFormatter; |
130
|
|
|
return $response; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function hasResponseFormatter(): bool |
134
|
|
|
{ |
135
|
|
|
return $this->responseFormatter !== null; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getResponse(): ResponseInterface |
139
|
|
|
{ |
140
|
|
|
return $this->response; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getData() |
144
|
|
|
{ |
145
|
|
|
if (is_callable($this->data)) { |
146
|
|
|
$this->data = ($this->data)(); |
147
|
|
|
} |
148
|
|
|
return is_object($this->data) ? clone $this->data : $this->data; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
private function formatResponse(): ResponseInterface |
152
|
|
|
{ |
153
|
|
|
return $this->responseFormatter->format($this); |
|
|
|
|
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.