Skip to content

Commit aab18b7

Browse files
committed
Add http promise interface
1 parent 684c839 commit aab18b7

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

src/HttpAsyncClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Http\Client;
44

5-
use Http\Promise\Promise;
5+
use Http\Client\Promise\HttpPromise;
66
use Psr\Http\Message\RequestInterface;
77

88
/**
@@ -19,7 +19,7 @@ interface HttpAsyncClient
1919
*
2020
* @param RequestInterface $request
2121
*
22-
* @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception.
22+
* @return HttpPromise Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception.
2323
*
2424
* @throws \Exception If processing the request is impossible (eg. bad configuration).
2525
*/

src/Promise/HttpFulfilledPromise.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Http\Client\Promise;
44

55
use Http\Client\Exception;
6-
use Http\Promise\Promise;
76
use Psr\Http\Message\ResponseInterface;
87

9-
final class HttpFulfilledPromise implements Promise
8+
final class HttpFulfilledPromise implements HttpPromise
109
{
1110
/**
1211
* @var ResponseInterface
@@ -42,7 +41,7 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
4241
*/
4342
public function getState()
4443
{
45-
return Promise::FULFILLED;
44+
return HttpPromise::FULFILLED;
4645
}
4746

4847
/**

src/Promise/HttpPromise.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Http\Client\Promise;
4+
5+
use Http\Client\Exception;
6+
use Http\Promise\Promise;
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
interface HttpPromise extends Promise
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*
14+
* @return HttpPromise A new resolved http promise with value of the executed callback (onFulfilled / onRejected).
15+
*/
16+
public function then(callable $onFulfilled = null, callable $onRejected = null);
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @return ResponseInterface Resolved response, null if $unwrap is set to false
22+
*
23+
* @throws Exception The http exception if $unwrap is set to true and the request failed.
24+
*/
25+
public function wait($unwrap = true);
26+
}

src/Promise/HttpRejectedPromise.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Http\Client\Promise;
44

55
use Http\Client\Exception;
6-
use Http\Promise\Promise;
76

8-
final class HttpRejectedPromise implements Promise
7+
final class HttpRejectedPromise implements HttpPromise
98
{
109
/**
1110
* @var Exception
@@ -41,7 +40,7 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
4140
*/
4241
public function getState()
4342
{
44-
return Promise::REJECTED;
43+
return HttpPromise::REJECTED;
4544
}
4645

4746
/**

0 commit comments

Comments
 (0)