Skip to content

Commit a7571a1

Browse files
committed
🔥 get rid of this mess NAO
1 parent 7ba678c commit a7571a1

File tree

5 files changed

+6
-171
lines changed

5 files changed

+6
-171
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"source": "https://github.com/chillerlan/php-httpinterface"
2020
},
2121
"provide": {
22-
"chillerlan/php-httpinterface": "2.0",
2322
"psr/http-client-implementation": "1.0",
2423
"psr/http-factory-implementation": "1.0",
2524
"psr/http-message-implementation": "1.0",

src/Psr18/HTTPClientAbstract.php

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,21 @@
1313
namespace chillerlan\HTTP\Psr18;
1414

1515
use chillerlan\HTTP\HTTPOptions;
16-
use chillerlan\HTTP\Psr17\{RequestFactory, ResponseFactory};
16+
use chillerlan\HTTP\Psr17\{ResponseFactory};
1717
use chillerlan\Settings\SettingsContainerInterface;
18-
use Psr\Http\Message\{RequestFactoryInterface, ResponseFactoryInterface, ResponseInterface};
18+
use Fig\Http\Message\RequestMethodInterface;
19+
use Psr\Http\Client\ClientInterface;
20+
use Psr\Http\Message\ResponseFactoryInterface;
1921
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
2022

21-
use function chillerlan\HTTP\Psr7\{merge_query, normalize_request_headers};
22-
use function chillerlan\HTTP\Psr17\create_stream;
23-
use function http_build_query, in_array, is_array, is_object, json_encode, strtoupper;
24-
25-
use const PHP_QUERY_RFC1738;
26-
27-
abstract class HTTPClientAbstract implements HTTPClientInterface, LoggerAwareInterface{
23+
abstract class HTTPClientAbstract implements ClientInterface, LoggerAwareInterface, RequestMethodInterface{
2824
use LoggerAwareTrait;
2925

3026
/**
3127
* @var \chillerlan\HTTP\HTTPOptions
3228
*/
3329
protected $options;
3430

35-
/**
36-
* @var \Psr\Http\Message\RequestFactoryInterface
37-
*/
38-
protected $requestFactory;
39-
4031
/**
4132
* @var \Psr\Http\Message\ResponseFactoryInterface
4233
*/
@@ -46,66 +37,17 @@ abstract class HTTPClientAbstract implements HTTPClientInterface, LoggerAwareInt
4637
* HTTPClientAbstract constructor.
4738
*
4839
* @param \chillerlan\Settings\SettingsContainerInterface|null $options
49-
* @param \Psr\Http\Message\RequestFactoryInterface|null $requestFactory
5040
* @param \Psr\Http\Message\ResponseFactoryInterface|null $responseFactory
5141
* @param \Psr\Log\LoggerInterface|null $logger
5242
*/
5343
public function __construct(
5444
SettingsContainerInterface $options = null,
55-
RequestFactoryInterface $requestFactory = null,
5645
ResponseFactoryInterface $responseFactory = null,
5746
LoggerInterface $logger = null
5847
){
5948
$this->options = $options ?? new HTTPOptions;
60-
$this->requestFactory = $requestFactory ?? new RequestFactory;
6149
$this->responseFactory = $responseFactory ?? new ResponseFactory;
6250
$this->logger = $logger ?? new NullLogger;
6351
}
6452

65-
/**
66-
* @deprecated: messy, under-used, missing flexibility
67-
*
68-
* @param string $uri
69-
* @param string|null $method
70-
* @param array|null $query
71-
* @param mixed|null $body
72-
* @param array|null $headers
73-
*
74-
* @return \Psr\Http\Message\ResponseInterface
75-
*/
76-
public function request(string $uri, string $method = null, array $query = null, $body = null, array $headers = null):ResponseInterface{
77-
$method = strtoupper($method ?? 'GET');
78-
$headers = normalize_request_headers($headers);
79-
$request = $this->requestFactory->createRequest($method, merge_query($uri, $query ?? []));
80-
81-
if(in_array($method, ['DELETE', 'PATCH', 'POST', 'PUT'], true) && $body !== null){
82-
83-
if(is_array($body) || is_object($body)){
84-
85-
if(!isset($headers['Content-type'])){
86-
$headers['Content-type'] = 'application/x-www-form-urlencoded';
87-
}
88-
89-
if($headers['Content-type'] === 'application/x-www-form-urlencoded'){
90-
$body = http_build_query($body, '', '&', PHP_QUERY_RFC1738);
91-
}
92-
elseif($headers['Content-type'] === 'application/json'){
93-
$body = json_encode($body);
94-
}
95-
else{
96-
$body = null; // @todo
97-
}
98-
99-
}
100-
101-
$request = $request->withBody(create_stream((string)$body));
102-
}
103-
104-
foreach($headers as $header => $value){
105-
$request = $request->withAddedHeader($header, $value);
106-
}
107-
108-
return $this->sendRequest($request);
109-
}
110-
11153
}

src/Psr18/HTTPClientInterface.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/Psr18/HTTPClientTestAbstract.php

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class HTTPClientTestAbstract extends TestCase{
2525
protected const USER_AGENT = 'chillerlanHttpTest/2.0';
2626

2727
/**
28-
* @var \chillerlan\HTTP\Psr18\HTTPClientInterface
28+
* @var \Psr\Http\Client\ClientInterface
2929
*/
3030
protected $http;
3131

@@ -47,65 +47,6 @@ public function testSendRequest(){
4747

4848
}
4949

50-
public function requestDataProvider():array {
51-
return [
52-
'get' => ['get', []],
53-
'post' => ['post', []],
54-
'post-json' => ['post', ['Content-type' => 'application/json']],
55-
'post-form' => ['post', ['Content-type' => 'application/x-www-form-urlencoded']],
56-
'put-json' => ['put', ['Content-type' => 'application/json']],
57-
'put-form' => ['put', ['Content-type' => 'application/x-www-form-urlencoded']],
58-
'patch-json' => ['patch', ['Content-type' => 'application/json']],
59-
'patch-form' => ['patch', ['Content-type' => 'application/x-www-form-urlencoded']],
60-
'delete' => ['delete', []],
61-
];
62-
}
63-
64-
/**
65-
* @dataProvider requestDataProvider
66-
*
67-
* @param $method
68-
* @param $extra_headers
69-
*/
70-
public function testRequest(string $method, array $extra_headers){
71-
72-
try{
73-
$response = $this->http->request(
74-
'https://httpbin.org/'.$method,
75-
$method,
76-
['foo' => 'bar'],
77-
['huh' => 'wtf'],
78-
['what' => 'nope'] + $extra_headers
79-
);
80-
}
81-
catch(Exception $e){
82-
$this->markTestSkipped('error: '.$e->getMessage());
83-
84-
return;
85-
}
86-
87-
$json = get_json($response);
88-
89-
if(!$json){
90-
$this->markTestSkipped('empty response');
91-
}
92-
else{
93-
$this->assertSame('https://httpbin.org/'.$method.'?foo=bar', $json->url);
94-
$this->assertSame('bar', $json->args->foo);
95-
$this->assertSame('nope', $json->headers->What);
96-
$this->assertSame($this::USER_AGENT, $json->headers->{'User-Agent'});
97-
98-
if(in_array($method, ['patch', 'post', 'put'])){
99-
100-
isset($extra_headers['content-type']) && $extra_headers['content-type'] === 'application/json'
101-
? $this->assertSame('wtf', $json->json->huh)
102-
: $this->assertSame('wtf', $json->form->huh);
103-
104-
}
105-
}
106-
107-
}
108-
10950
public function testNetworkError(){
11051
$this->expectException(ClientExceptionInterface::class);
11152

tests/Psr18/LoggingClientTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,4 @@ public function log($level, $message, array $context = []){
3131
$this->http = new LoggingClient($this->http, $logger);
3232
}
3333

34-
/**
35-
* @dataProvider requestDataProvider
36-
*
37-
* @param $method
38-
* @param $extra_headers
39-
*/
40-
public function testRequest(string $method, array $extra_headers){
41-
$this->markTestSkipped('N/A');
42-
}
43-
4434
}

0 commit comments

Comments
 (0)