Skip to content

Commit 2305dea

Browse files
committed
:octocat:
1 parent 8fa4792 commit 2305dea

File tree

6 files changed

+127
-16
lines changed

6 files changed

+127
-16
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chillerlan/php-httpinterface",
3-
"description": "A http PSR-7/17 client/interface for PHP7.2+",
3+
"description": "A http PSR-7/17/18 client/interface for PHP7.2+",
44
"license": "MIT",
55
"type": "library",
66
"keywords": [
@@ -20,15 +20,16 @@
2020
},
2121
"provide": {
2222
"chillerlan/php-httpinterface": "2.0",
23-
"psr/http-message-implementation": "1.0",
24-
"psr/http-factory-implementation": "1.0"
23+
"psr/http-client-implementation": "1.0",
24+
"psr/http-factory-implementation": "1.0",
25+
"psr/http-message-implementation": "1.0"
2526
},
2627
"require": {
2728
"php": "^7.2",
2829
"ext-curl":"*",
2930
"chillerlan/php-settings-container":"^1.0",
3031
"fig/http-message-util":"^1.1",
31-
"php-http/httplug":"^1.1",
32+
"psr/http-client":"dev-master",
3233
"psr/http-message": "^1.0",
3334
"psr/http-factory":"^1.0",
3435
"psr/log": "^1.0"

src/ClientException.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Class ClientException
4+
*
5+
* @filesource ClientException.php
6+
* @created 10.09.2018
7+
* @package chillerlan\HTTP
8+
* @author smiley <smiley@chillerlan.net>
9+
* @copyright 2018 smiley
10+
* @license MIT
11+
*/
12+
13+
namespace chillerlan\HTTP;
14+
15+
use Psr\Http\Client\ClientExceptionInterface;
16+
use Exception;
17+
18+
class ClientException extends Exception implements ClientExceptionInterface{
19+
20+
}

src/CurlClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use chillerlan\HTTP\Psr17\{RequestFactory, ResponseFactory, StreamFactory};
1616
use chillerlan\Settings\SettingsContainerInterface;
1717
use Psr\Http\Message\{RequestFactoryInterface, RequestInterface, ResponseFactoryInterface, ResponseInterface, StreamFactoryInterface};
18-
use Http\Client\Exception\{NetworkException, RequestException};
1918

2019
class CurlClient implements HTTPClientInterface{
2120

@@ -66,8 +65,8 @@ public function __construct(
6665
*
6766
* @return \Psr\Http\Message\ResponseInterface
6867
*
69-
* @throws \Http\Client\Exception If an error happens during processing the request.
70-
* @throws \Exception If processing the request is impossible (eg. bad configuration).
68+
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens during processing the request.
69+
* @throws \Exception If processing the request is impossible (eg. bad configuration).
7170
*/
7271
public function sendRequest(RequestInterface $request):ResponseInterface{
7372
$handle = new CurlHandle($request, $this->responseFactory->createResponse(), $this->options);

src/HTTPClientInterface.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313
namespace chillerlan\HTTP;
1414

1515
use Fig\Http\Message\RequestMethodInterface;
16-
use Http\Client\HttpClient;
16+
use Psr\Http\Client\ClientInterface;
1717
use Psr\Http\Message\ResponseInterface;
1818

19-
/**
20-
* ...waiting for PSR-18, going with HTTPlug for now
21-
*
22-
* @link https://github.com/php-fig/fig-standards/tree/master/proposed/http-client/
23-
*/
24-
interface HTTPClientInterface extends HttpClient, RequestMethodInterface{
19+
interface HTTPClientInterface extends ClientInterface, RequestMethodInterface{
2520

2621
/**
2722
* @param string $uri
@@ -32,8 +27,8 @@ interface HTTPClientInterface extends HttpClient, RequestMethodInterface{
3227
*
3328
* @return \Psr\Http\Message\ResponseInterface
3429
*
35-
* @throws \Http\Client\Exception If an error happens during processing the request.
36-
* @throws \Exception If processing the request is impossible (eg. bad configuration).
30+
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens during processing the request.
31+
* @throws \Exception If processing the request is impossible (eg. bad configuration).
3732
*/
3833
public function request(string $uri, string $method = null, array $query = null, $body = null, array $headers = null):ResponseInterface;
3934

src/NetworkException.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Class NetworkException
4+
*
5+
* @filesource NetworkException.php
6+
* @created 10.09.2018
7+
* @package chillerlan\HTTP
8+
* @author smiley <smiley@chillerlan.net>
9+
* @copyright 2018 smiley
10+
* @license MIT
11+
*/
12+
13+
namespace chillerlan\HTTP;
14+
15+
use Exception;
16+
use Psr\Http\Client\NetworkExceptionInterface;
17+
use Psr\Http\Message\RequestInterface;
18+
19+
class NetworkException extends ClientException implements NetworkExceptionInterface{
20+
21+
/**
22+
* @var \Psr\Http\Message\RequestInterface
23+
*/
24+
private $request;
25+
26+
/**
27+
* @param string $message
28+
* @param \Psr\Http\Message\RequestInterface $request
29+
* @param \Exception|null $previous
30+
*/
31+
public function __construct(string $message, RequestInterface $request, Exception $previous = null){
32+
$this->request = $request;
33+
34+
parent::__construct($message, 0, $previous);
35+
}
36+
37+
/**
38+
* Returns the request.
39+
*
40+
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
41+
*
42+
* @return \Psr\Http\Message\RequestInterface
43+
*/
44+
public function getRequest():RequestInterface{
45+
return $this->request;
46+
}
47+
48+
}

src/RequestException.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Class RequestException
4+
*
5+
* @filesource RequestException.php
6+
* @created 10.09.2018
7+
* @package chillerlan\HTTP
8+
* @author smiley <smiley@chillerlan.net>
9+
* @copyright 2018 smiley
10+
* @license MIT
11+
*/
12+
13+
namespace chillerlan\HTTP;
14+
15+
use Exception;
16+
use Psr\Http\Client\RequestExceptionInterface;
17+
use Psr\Http\Message\RequestInterface;
18+
19+
class RequestException extends ClientException implements RequestExceptionInterface{
20+
21+
/**
22+
* @var \Psr\Http\Message\RequestInterface
23+
*/
24+
private $request;
25+
26+
/**
27+
* @param string $message
28+
* @param \Psr\Http\Message\RequestInterface $request
29+
* @param \Exception|null $previous
30+
*/
31+
public function __construct(string $message, RequestInterface $request, Exception $previous = null){
32+
$this->request = $request;
33+
34+
parent::__construct($message, 0, $previous);
35+
}
36+
37+
/**
38+
* Returns the request.
39+
*
40+
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
41+
*
42+
* @return \Psr\Http\Message\RequestInterface
43+
*/
44+
public function getRequest():RequestInterface{
45+
return $this->request;
46+
}
47+
48+
}

0 commit comments

Comments
 (0)