Skip to content

Commit fc11ea1

Browse files
committed
updates
1 parent 6c1e7d0 commit fc11ea1

File tree

8 files changed

+73
-11
lines changed

8 files changed

+73
-11
lines changed

.github/workflows/php.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Composer
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: '7.4'
19+
extensions: xdebug, mbstring
20+
21+
- name: composer install
22+
run: composer install --no-progress
23+
24+
- name: composer tests
25+
run: composer test

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codin/http-client",
33
"description": "Tiny PSR-18 Http Client",
4-
"license": "Apache-2.0",
4+
"license": "MIT",
55
"type": "library",
66
"minimum-stability": "dev",
77
"prefer-stable": true,

license.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Codin’ Co.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Simple http client
22

3+
![version](https://img.shields.io/github/v/tag/codin/http-client)
4+
![workflow](https://img.shields.io/github/workflow/status/codin/http-client/Composer)
5+
![license](https://img.shields.io/github/license/codin/http-client)
6+
37
Example
48

59
```php

spec/RequestBuilderSpec.php

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

33
namespace spec\Codin\HttpClient;
44

5+
use function json_encode;
56
use PhpSpec\ObjectBehavior;
67
use Prophecy\Argument\Token\TypeToken;
78
use Psr\Http\Message\ServerRequestFactoryInterface;
89
use Psr\Http\Message\ServerRequestInterface;
910
use Psr\Http\Message\StreamFactoryInterface;
10-
use Psr\Http\Message\UriInterface;
1111
use Psr\Http\Message\StreamInterface;
12-
use function json_encode;
12+
use Psr\Http\Message\UriInterface;
1313

1414
class RequestBuilderSpec extends ObjectBehavior
1515
{

src/Exceptions/ClientError.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Codin\HttpClient\Exceptions;
66

7+
use ErrorException;
8+
use Psr\Http\Client\RequestExceptionInterface;
79
use Psr\Http\Message\RequestInterface;
810
use Psr\Http\Message\ResponseInterface;
911

10-
class ClientError extends TransportError
12+
class ClientError extends ErrorException implements RequestExceptionInterface
1113
{
1214
protected RequestInterface $request;
1315

src/Exceptions/TransportError.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
namespace Codin\HttpClient\Exceptions;
66

77
use ErrorException;
8+
use Psr\Http\Client\NetworkExceptionInterface;
9+
use Psr\Http\Message\RequestInterface;
810

9-
class TransportError extends ErrorException
11+
class TransportError extends ErrorException implements NetworkExceptionInterface
1012
{
13+
protected RequestInterface $request;
14+
15+
public function __construct(string $message, int $code, RequestInterface $request)
16+
{
17+
$this->request = $request;
18+
parent::__construct($message, $code);
19+
}
20+
21+
public function getRequest(): RequestInterface
22+
{
23+
return $this->request;
24+
}
1125
}

src/HttpClient.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function buildOptions(RequestInterface $request): array
112112
};
113113
}
114114

115-
return $this->options + $options;
115+
return array_merge($options, $this->options);
116116
}
117117

118118
protected function parseHeaders(ResponseInterface $response, StreamInterface $headers): ResponseInterface
@@ -172,11 +172,7 @@ static function ($session, string $data) use ($body): int {
172172
curl_reset($this->session);
173173

174174
if (false === $result) {
175-
throw new Exceptions\TransportError(sprintf(
176-
'cURL error (%s): %s',
177-
curl_errno($this->session),
178-
curl_error($this->session)
179-
));
175+
throw new Exceptions\TransportError(curl_error($this->session), curl_errno($this->session), $request);
180176
}
181177

182178
$response = $this->buildResponse($headers, $body);

0 commit comments

Comments
 (0)