Skip to content

Commit a4f779e

Browse files
authored
Merge pull request #44 from sunrise-php/release/v2.0.0
v2
2 parents 7da8dbd + 06ad8f3 commit a4f779e

21 files changed

+1054
-421
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ indent_size = 4
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
1313

14-
[*.yml]
14+
[*{.json,.yml}]
1515
indent_size = 2

.scrutinizer.yml

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,34 @@ build:
33
nodes:
44
analysis:
55
environment:
6-
php: 8.1
6+
php: 8.3.16
77
tests:
88
override:
99
- php-scrutinizer-run
1010
coverage:
1111
environment:
12-
php: 8.1
12+
php: 8.3.16
1313
tests:
1414
override:
1515
- command: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-clover coverage.xml
1616
coverage:
1717
file: coverage.xml
1818
format: clover
19-
php80:
19+
php83:
2020
environment:
21-
php: 8.0
21+
php: 8.3.16
2222
tests:
2323
override:
24-
- command: php vendor/bin/phpunit
25-
php74:
24+
- command: composer test
25+
php82:
2626
environment:
27-
php: 7.4
27+
php: 8.2.27
2828
tests:
2929
override:
30-
- command: php vendor/bin/phpunit
31-
php73:
30+
- command: composer test
31+
php81:
3232
environment:
33-
php: 7.3
33+
php: 8.1.31
3434
tests:
3535
override:
36-
- command: php vendor/bin/phpunit
37-
php72:
38-
environment:
39-
php: 7.2
40-
tests:
41-
override:
42-
- command: php vendor/bin/phpunit
43-
php71:
44-
environment:
45-
php: 7.1
46-
variables:
47-
APACHE_RUN_DIR: /var/run/apache2
48-
tests:
49-
override:
50-
- command: php vendor/bin/phpunit
36+
- command: composer test

README.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# Simple HTTP cURL client for PHP 7.1+ based on PSR-18
1+
# Simple HTTP cURL client for PHP 8.1+ implementing PSR-18
22

33
[![Build Status](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/build.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/build-status/master)
44
[![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/?branch=master)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-client-curl/?branch=master)
66
[![Total Downloads](https://poser.pugx.org/sunrise/http-client-curl/downloads?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)
7-
[![Latest Stable Version](https://poser.pugx.org/sunrise/http-client-curl/v/stable?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)
8-
[![License](https://poser.pugx.org/sunrise/http-client-curl/license?format=flat)](https://packagist.org/packages/sunrise/http-client-curl)
97

108
---
119

@@ -15,19 +13,19 @@
1513
composer require sunrise/http-client-curl
1614
```
1715

18-
## QuickStart
16+
## Quick Start
1917

2018
```bash
21-
composer require sunrise/http-factory
19+
composer require sunrise/http-message
2220
```
2321

2422
```php
2523
use Sunrise\Http\Client\Curl\Client;
26-
use Sunrise\Http\Factory\RequestFactory;
27-
use Sunrise\Http\Factory\ResponseFactory;
24+
use Sunrise\Http\Message\RequestFactory;
25+
use Sunrise\Http\Message\ResponseFactory;
2826

2927
$client = new Client(new ResponseFactory());
30-
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
28+
$request = (new RequestFactory())->createRequest('GET', 'https://www.php.net/');
3129
$response = $client->sendRequest($request);
3230

3331
echo $response->getStatusCode(), PHP_EOL;
@@ -38,42 +36,45 @@ echo $response->getStatusCode(), PHP_EOL;
3836
> https://www.php.net/manual/ru/curl.constants.php
3937
4038
```php
39+
use Sunrise\Http\Client\Curl\Client;
40+
use Sunrise\Http\Message\ResponseFactory;
41+
42+
use const CURLOPT_AUTOREFERER;
43+
use const CURLOPT_FOLLOWLOCATION;
44+
4145
$client = new Client(new ResponseFactory(), [
42-
\CURLOPT_AUTOREFERER => true,
43-
\CURLOPT_FOLLOWLOCATION => true,
46+
CURLOPT_AUTOREFERER => true,
47+
CURLOPT_FOLLOWLOCATION => true,
4448
]);
4549
```
4650

4751
### Parallel execution of multiple requests
4852

4953
```php
50-
$requests = [
51-
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
52-
(new RequestFactory)->createRequest('GET', 'http://php.net/'),
53-
];
54+
use Sunrise\Http\Client\Curl\Client;
55+
use Sunrise\Http\Client\Curl\MultiRequest;
56+
use Sunrise\Http\Message\RequestFactory;
57+
use Sunrise\Http\Message\ResponseFactory;
5458

5559
$client = new Client(new ResponseFactory());
56-
$responses = $client->sendRequests(...$request);
5760

58-
foreach ($responses as $i => $response) {
59-
// note that you can get the response's request by its index...
60-
echo sprintf('%s => %d', $requests[$i]->getUri(), $response->getStatusCode()), PHP_EOL;
61+
$multiRequest = new MultiRequest(
62+
foo: (new RequestFactory())->createRequest('GET', 'https://www.php.net/'),
63+
bar: (new RequestFactory())->createRequest('GET', 'https://www.php.net/'),
64+
)
65+
66+
$responses = $client->sendRequest($multiRequest)->getResponses();
67+
68+
foreach ($responses as $key => $response) {
69+
// Note that you can get the response's request by its key...
70+
echo sprintf('%s => %d', $multiRequest->getRequests()[$key]->getUri(), $response->getStatusCode()), PHP_EOL;
6171
}
6272
```
6373

6474
---
6575

66-
## Test run
76+
## Tests
6777

6878
```bash
6979
composer test
7080
```
71-
72-
## Useful links
73-
74-
* http://php.net/manual/en/intro.curl.php
75-
* https://curl.haxx.se/libcurl/c/libcurl-errors.html
76-
* https://www.php-fig.org/psr/psr-2/
77-
* https://www.php-fig.org/psr/psr-7/
78-
* https://www.php-fig.org/psr/psr-17/
79-
* https://www.php-fig.org/psr/psr-18/

composer.json

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,70 @@
11
{
2-
"name": "sunrise/http-client-curl",
3-
"homepage": "https://github.com/sunrise-php/http-client-curl",
4-
"description": "Simple HTTP cURL client for PHP 7.1+ based on PSR-18",
5-
"license": "MIT",
6-
"keywords": [
7-
"fenric",
8-
"sunrise",
9-
"http",
10-
"client",
11-
"curl",
12-
"psr2",
13-
"psr7",
14-
"psr17",
15-
"psr18",
16-
"php7",
17-
"php8"
18-
],
19-
"authors": [
20-
{
21-
"name": "Anatoly Fenric",
22-
"email": "[email protected]",
23-
"homepage": "https://github.com/fenric"
24-
},
25-
{
26-
"name": "李昀陞 (Peter)",
27-
"email": "[email protected]",
28-
"homepage": "https://github.com/peter279k"
29-
}
30-
],
31-
"provide": {
32-
"psr/http-client-implementation": "1.0",
33-
"php-http/client-implementation": "1.0"
2+
"name": "sunrise/http-client-curl",
3+
"homepage": "https://github.com/sunrise-php/http-client-curl",
4+
"description": "Simple HTTP cURL client for PHP 8.1+ implementing PSR-18.",
5+
"license": "MIT",
6+
"keywords": [
7+
"fenric",
8+
"sunrise",
9+
"http",
10+
"client",
11+
"curl",
12+
"psr-18"
13+
],
14+
"authors": [
15+
{
16+
"name": "Anatoly Nekhay",
17+
"email": "[email protected]",
18+
"homepage": "https://github.com/fenric"
3419
},
35-
"require": {
36-
"php": ">=7.1",
37-
"ext-curl": "*",
38-
"psr/http-client": "^1.0",
39-
"psr/http-factory": "^1.0",
40-
"psr/http-message": "^1.0"
41-
},
42-
"require-dev": {
43-
"phpunit/phpunit": "7.5.20|9.5.0",
44-
"sunrise/coding-standard": "1.0.0",
45-
"sunrise/http-factory": "2.0.2"
46-
},
47-
"autoload": {
48-
"psr-4": {
49-
"Sunrise\\Http\\Client\\Curl\\": "src/"
50-
}
51-
},
52-
"scripts": {
53-
"test": [
54-
"phpcs",
55-
"psalm",
56-
"XDEBUG_MODE=coverage phpunit --coverage-text --colors=always"
57-
],
58-
"build": [
59-
"phpdoc -d src/ -t phpdoc/",
60-
"XDEBUG_MODE=coverage phpunit --coverage-html coverage/"
61-
]
20+
{
21+
"name": "李昀陞 (Peter)",
22+
"email": "[email protected]",
23+
"homepage": "https://github.com/peter279k"
24+
}
25+
],
26+
"require": {
27+
"php": ">=8.1",
28+
"ext-curl": "*",
29+
"psr/http-client": "^1.0",
30+
"psr/http-factory": "^1.0",
31+
"psr/http-message": "^1.0 || ^2.0"
32+
},
33+
"require-dev": {
34+
"php-di/php-di": "^7.0",
35+
"phpstan/phpstan": "^2.1",
36+
"phpunit/phpunit": "^10.5",
37+
"squizlabs/php_codesniffer": "^3.11",
38+
"sunrise/http-message": "^3.4",
39+
"vimeo/psalm": "^6.5"
40+
},
41+
"provide": {
42+
"psr/http-client-implementation": "1.0",
43+
"php-http/client-implementation": "1.0"
44+
},
45+
"autoload": {
46+
"psr-4": {
47+
"Sunrise\\Http\\Client\\Curl\\": "src/"
48+
}
49+
},
50+
"autoload-dev": {
51+
"psr-4": {
52+
"Sunrise\\Http\\Client\\Curl\\Tests\\": "tests/"
6253
}
54+
},
55+
"scripts": {
56+
"phpcs": "@php phpcs --colors",
57+
"psalm": "@php psalm --no-cache",
58+
"phpstan": "@php phpstan analyse src --configuration=phpstan.neon.php --level=9 --memory-limit=-1",
59+
"phpunit": "@php phpunit --colors=always",
60+
"test": [
61+
"@phpcs",
62+
"@psalm",
63+
"@phpstan",
64+
"@phpunit"
65+
]
66+
},
67+
"config": {
68+
"sort-packages": true
69+
}
6370
}

phpcs.xml.dist

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?xml version="1.0"?>
22
<ruleset name="Sunrise Coding Standard">
3-
<rule ref="./vendor/sunrise/coding-standard/ruleset.xml"/>
3+
<rule ref="PSR12" />
4+
<rule ref="Generic.PHP.RequireStrictTypes" />
5+
6+
<rule ref="Generic.Files.LineLength">
7+
<exclude-pattern>resources/*</exclude-pattern>
8+
<exclude-pattern>tests/*</exclude-pattern>
9+
</rule>
410

511
<file>src</file>
612
<file>tests</file>

phpstan.neon.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$config = [
6+
'includes' => [
7+
],
8+
'parameters' => [
9+
'phpVersion' => PHP_VERSION_ID,
10+
],
11+
];
12+
13+
return $config;

phpunit.xml.dist

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<?xml version="1.0"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
5-
>
6-
<coverage>
7-
<include>
8-
<directory>./src</directory>
9-
</include>
10-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
113
<testsuites>
124
<testsuite name="sunrise/http-client-curl">
135
<directory>./tests/</directory>
146
</testsuite>
157
</testsuites>
8+
<source>
9+
<include>
10+
<directory>./src</directory>
11+
</include>
12+
</source>
1613
</phpunit>

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns="https://getpsalm.org/schema/config"
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
phpVersion="8.1"
78
>
89
<projectFiles>
910
<directory name="src" />
1011
<ignoreFiles>
1112
<directory name="vendor" />
1213
</ignoreFiles>
1314
</projectFiles>
15+
16+
<issueHandlers>
17+
<PossiblyUnusedMethod errorLevel="suppress" />
18+
<UnusedClass errorLevel="suppress" />
19+
</issueHandlers>
1420
</psalm>

resources/definitions/client.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Psr\Http\Client\ClientInterface;
6+
use Psr\Http\Message\ResponseFactoryInterface;
7+
use Sunrise\Http\Client\Curl\Client;
8+
9+
use function DI\create;
10+
use function DI\get;
11+
12+
return [
13+
'curl.options' => [],
14+
'curl.multi_select_timeout' => null,
15+
'curl.multi_select_sleep_duration' => null,
16+
17+
ClientInterface::class => create(Client::class)
18+
->constructor(
19+
responseFactory: get(ResponseFactoryInterface::class),
20+
curlOptions: get('curl.options'),
21+
curlMultiSelectTimeout: get('curl.multi_select_timeout'),
22+
curlMultiSelectSleepDuration: get('curl.multi_select_sleep_duration'),
23+
),
24+
];

0 commit comments

Comments
 (0)