1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
<?php
namespace GuzzleHttp\Message;
use GuzzleHttp\Ring\Future\MagicFutureTrait;
use GuzzleHttp\Ring\Future\FutureInterface;
use GuzzleHttp\Stream\StreamInterface;
/**
* Represents a response that has not been fulfilled.
*
* When created, you must provide a function that is used to dereference the
* future result and return it's value. The function has no arguments and MUST
* return an instance of a {@see GuzzleHttp\Message\ResponseInterface} object.
*
* You can optionally provide a function in the constructor that can be used to
* cancel the future from completing if possible. This function has no
* arguments and returns a boolean value representing whether or not the
* response could be cancelled.
*
* @property ResponseInterface $_value
*/
class FutureResponse implements ResponseInterface, FutureInterface
{
use MagicFutureTrait;
/**
* Returns a FutureResponse that wraps another future.
*
* @param FutureInterface $future Future to wrap with a new future
* @param callable $onFulfilled Invoked when the future fulfilled
* @param callable $onRejected Invoked when the future rejected
* @param callable $onProgress Invoked when the future progresses
*
* @return FutureResponse
*/
public static function proxy(
FutureInterface $future,
callable $onFulfilled = null,
callable $onRejected = null,
callable $onProgress = null
) {
return new FutureResponse(
$future->then($onFulfilled, $onRejected, $onProgress),
[$future, 'wait'],
[$future, 'cancel']
);
}
public function getStatusCode()
{
return $this->_value->getStatusCode();
}
public function setStatusCode($code)
{
$this->_value->setStatusCode($code);
}
public function getReasonPhrase()
{
return $this->_value->getReasonPhrase();
}
public function setReasonPhrase($phrase)
{
$this->_value->setReasonPhrase($phrase);
}
public function getEffectiveUrl()
{
return $this->_value->getEffectiveUrl();
}
public function setEffectiveUrl($url)
{
$this->_value->setEffectiveUrl($url);
}
public function json(array $config = [])
{
return $this->_value->json($config);
}
public function xml(array $config = [])
{
return $this->_value->xml($config);
}
public function __toString()
{
try {
return $this->_value->__toString();
} catch (\Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
return '';
}
}
public function getProtocolVersion()
{
return $this->_value->getProtocolVersion();
}
public function setBody(StreamInterface $body = null)
{
$this->_value->setBody($body);
}
public function getBody()
{
return $this->_value->getBody();
}
public function getHeaders()
{
return $this->_value->getHeaders();
}
public function getHeader($header)
{
return $this->_value->getHeader($header);
}
public function getHeaderAsArray($header)
{
return $this->_value->getHeaderAsArray($header);
}
public function hasHeader($header)
{
return $this->_value->hasHeader($header);
}
public function removeHeader($header)
{
$this->_value->removeHeader($header);
}
public function addHeader($header, $value)
{
$this->_value->addHeader($header, $value);
}
public function addHeaders(array $headers)
{
$this->_value->addHeaders($headers);
}
public function setHeader($header, $value)
{
$this->_value->setHeader($header, $value);
}
public function setHeaders(array $headers)
{
$this->_value->setHeaders($headers);
}
}
|