File tree Expand file tree Collapse file tree 3 files changed +13
-26
lines changed Expand file tree Collapse file tree 3 files changed +13
-26
lines changed Original file line number Diff line number Diff line change 12
12
],
13
13
"require" : {
14
14
"php" : " >=5.4" ,
15
- "php-http/httplug" : " ^ 1.0.0-alpha2 " ,
15
+ "php-http/httplug" : " 1.0.0-alpha3 " ,
16
16
"php-http/message-factory" : " ^0.4@dev" ,
17
17
"react/http-client" : " ^0.4.8" ,
18
18
"react/dns" : " ^0.4.1" ,
Original file line number Diff line number Diff line change 9
9
use React \HttpClient \Response as ReactResponse ;
10
10
use Http \Client \HttpClient ;
11
11
use Http \Client \HttpAsyncClient ;
12
- use Http \Client \Promise ;
13
12
use Http \Client \Exception \HttpException ;
14
13
use Http \Client \Exception \RequestException ;
14
+ use Http \Promise \Promise ;
15
15
use Http \Message \MessageFactory ;
16
16
use Psr \Http \Message \RequestInterface ;
17
17
use Psr \Http \Message \StreamInterface ;
@@ -62,13 +62,8 @@ public function __construct(
62
62
public function sendRequest (RequestInterface $ request )
63
63
{
64
64
$ promise = $ this ->sendAsyncRequest ($ request );
65
- $ promise ->wait ();
66
65
67
- if ($ promise ->getState () == Promise::REJECTED ) {
68
- throw $ promise ->getException ();
69
- }
70
-
71
- return $ promise ->getResponse ();
66
+ return $ promise ->wait ();
72
67
}
73
68
74
69
/**
Original file line number Diff line number Diff line change 4
4
5
5
use React \EventLoop \LoopInterface ;
6
6
use React \Promise \PromiseInterface as ReactPromise ;
7
- use Http \Client \Promise ;
8
7
use Http \Client \Exception ;
8
+ use Http \Promise \Promise ;
9
9
use Psr \Http \Message \ResponseInterface ;
10
10
11
11
/**
@@ -91,22 +91,6 @@ public function getState()
91
91
return $ this ->state ;
92
92
}
93
93
94
- /**
95
- * {@inheritdoc}
96
- */
97
- public function getResponse ()
98
- {
99
- return $ this ->response ;
100
- }
101
-
102
- /**
103
- * {@inheritdoc}
104
- */
105
- public function getException ()
106
- {
107
- return $ this ->exception ;
108
- }
109
-
110
94
/**
111
95
* Set EventLoop used for synchronous processing
112
96
* @param LoopInterface $loop
@@ -121,13 +105,21 @@ public function setLoop(LoopInterface $loop)
121
105
/**
122
106
* {@inheritdoc}
123
107
*/
124
- public function wait ()
108
+ public function wait ($ unwrap = true )
125
109
{
126
110
if (null === $ this ->loop ) {
127
111
throw new \LogicException ("You must set the loop before wait! " );
128
112
}
129
113
while (Promise::PENDING === $ this ->getState ()) {
130
114
$ this ->loop ->tick ();
131
115
}
116
+
117
+ if ($ unwrap ) {
118
+ if (Promise::REJECTED == $ this ->getState ()) {
119
+ throw $ this ->exception ;
120
+ }
121
+
122
+ return $ this ->response ;
123
+ }
132
124
}
133
125
}
You can’t perform that action at this time.
0 commit comments