Skip to content

Commit a723cff

Browse files
committed
First commit
0 parents  commit a723cff

File tree

11 files changed

+384
-0
lines changed

11 files changed

+384
-0
lines changed

.docheader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file is part of php-fast-forward/http-client.
3+
*
4+
* This source file is subject to the license bundled
5+
* with this source code in the file LICENSE.
6+
*
7+
* @link https://github.com/php-fast-forward/http-client
8+
* @copyright Copyright (c) 2025-%year% Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
9+
* @license https://opensource.org/licenses/MIT MIT License
10+
*/

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
/.github/ export-ignore
3+
/tests/ export-ignore
4+
/.docheader export-ignore
5+
/.dockerignore export-ignore
6+
/.editorconfig export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/.php-cs-fixer.php export-ignore
10+
/docker-compose export-ignore
11+
/Dockerfile export-ignore
12+
/infection.json5 export-ignore
13+
/phpunit.xml export-ignore

.github/workflows/tests.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Run PHPUnit Tests
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
jobs:
19+
tests:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Cache Composer dependencies
26+
uses: actions/cache@v3
27+
with:
28+
path: /tmp/composer-cache
29+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
30+
31+
- name: Install dependencies
32+
uses: php-actions/composer@v6
33+
env:
34+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
35+
with:
36+
php_version: '8.4'
37+
38+
- name: Run PHPUnit tests
39+
uses: php-actions/phpunit@v3
40+
env:
41+
XDEBUG_MODE: coverage
42+
with:
43+
php_version: '8.4'
44+
php_extensions: pcov
45+
46+
- name: Ensure minimum code coverage
47+
env:
48+
MINIMUM_COVERAGE: 80
49+
run: |
50+
COVERAGE=$(php -r '
51+
$xml = new SimpleXMLElement(file_get_contents("public/coverage/clover.xml"));
52+
$m = $xml->project->metrics;
53+
$pct = (int) round(((int) $m["coveredstatements"]) * 100 / (int) $m["statements"]);
54+
echo $pct;
55+
')
56+
echo "Coverage: ${COVERAGE}%"
57+
if [ "${COVERAGE}" -lt ${{ env.MINIMUM_COVERAGE }} ]; then
58+
echo "Code coverage below ${{ env.MINIMUM_COVERAGE }}% threshold."
59+
exit 1
60+
fi
61+
62+
- name: Upload artifact
63+
if: github.ref == 'refs/heads/main'
64+
uses: actions/upload-pages-artifact@v3
65+
with:
66+
path: public/coverage
67+
68+
deploy:
69+
if: github.ref == 'refs/heads/main'
70+
needs: tests
71+
environment:
72+
name: github-pages
73+
url: ${{ steps.deployment.outputs.page_url }}
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Deploy to GitHub Pages
77+
id: deployment
78+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
public/
3+
vendor/
4+
composer.lock
5+
*.cache

.php-cs-fixer.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-client.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-client
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use CoiSA\PhpCsFixer\PhpCsFixer;
17+
18+
$paths = [
19+
__FILE__,
20+
__DIR__,
21+
];
22+
23+
$header = file_get_contents(__DIR__ . '/.docheader');
24+
25+
return PhpCsFixer::create($paths, $header);

LICENSE

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

composer.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "fast-forward/http-client",
3+
"description": "Fast Forward PSR-18 HTTP Client Factory",
4+
"license": "MIT",
5+
"type": "library",
6+
"authors": [
7+
{
8+
"name": "Felipe Sayão Lobato Abreu",
9+
"email": "github@mentordosnerds.com"
10+
}
11+
],
12+
"homepage": "https://github.com/php-fast-forward",
13+
"support": {
14+
"issues": "https://github.com/php-fast-forward/http-client/issues",
15+
"source": "https://github.com/php-fast-forward/http-client"
16+
},
17+
"require": {
18+
"php": "^8.1",
19+
"container-interop/service-provider": "^0.4.1",
20+
"fast-forward/container": "^1.4",
21+
"psr/http-client": "^1.0",
22+
"psr/http-factory": "^1.1",
23+
"symfony/http-client": "^7.3"
24+
},
25+
"require-dev": {
26+
"coisa/php-cs-fixer": "^2.1",
27+
"phpspec/prophecy-phpunit": "^2.3",
28+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5"
29+
},
30+
"minimum-stability": "stable",
31+
"autoload": {
32+
"psr-4": {
33+
"FastForward\\Http\\Client\\": "src/"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"FastForward\\Http\\Client\\Tests\\": "tests/"
39+
}
40+
},
41+
"config": {
42+
"sort-packages": true
43+
},
44+
"extra": {
45+
"branch-alias": {
46+
"dev-main": "1.x-dev"
47+
}
48+
},
49+
"scripts": {
50+
"cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff",
51+
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
52+
"mutation-testing": "infection --threads=4",
53+
"pre-commit": [
54+
"@cs-check",
55+
"@static-analysis",
56+
"@tests"
57+
],
58+
"static-analysis": "phpstan analyse --level 5 src",
59+
"tests": "phpunit --testdox"
60+
}
61+
}

phpunit.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
executionOrder="depends,defects"
6+
shortenArraysForExportThreshold="10"
7+
requireCoverageMetadata="true"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
failOnPhpunitDeprecation="true"
12+
failOnRisky="true"
13+
failOnWarning="true">
14+
<testsuites>
15+
<testsuite name="Fast Forward Http Client Test Suite">
16+
<directory>tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
24+
<coverage>
25+
<report>
26+
<clover outputFile="public/coverage/clover.xml"/>
27+
<html outputDirectory="public/coverage" lowUpperBound="35" highLowerBound="70"/>
28+
<text outputFile="php://stdout"/>
29+
</report>
30+
</coverage>
31+
<logging>
32+
<testdoxHtml outputFile="public/coverage/testdox.html"/>
33+
</logging>
34+
</phpunit>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-client.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-client
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
namespace FastForward\Http\Client\ServiceProvider;
17+
18+
use FastForward\Container\Factory\InvokableFactory;
19+
use FastForward\Container\Factory\MethodFactory;
20+
use Interop\Container\ServiceProviderInterface;
21+
use Psr\Http\Client\ClientInterface;
22+
use Psr\Http\Message\ResponseFactoryInterface;
23+
use Psr\Http\Message\StreamFactoryInterface;
24+
use Symfony\Component\HttpClient\HttpClient;
25+
use Symfony\Component\HttpClient\Psr18Client;
26+
27+
/**
28+
* Class HttpClientServiceProvider.
29+
*
30+
* Provides a PSR-compliant HTTP client service provider for dependency injection containers.
31+
* This service provider SHALL register factories for HTTP client services.
32+
* It MUST implement the ServiceProviderInterface to allow standardized service registration.
33+
*/
34+
final class HttpClientServiceProvider implements ServiceProviderInterface
35+
{
36+
/**
37+
* Retrieves an array of service factories.
38+
*
39+
* This method MUST return an associative array where the key is the service name or interface
40+
* and the value is a callable or factory responsible for creating the service.
41+
* The array returned SHALL register the default Symfony HttpClient and a PSR-18 compatible client.
42+
*
43+
* @return array<class-string, callable> an associative array of service factories
44+
*/
45+
public function getFactories(): array
46+
{
47+
return [
48+
HttpClient::class => new MethodFactory(HttpClient::class, 'create'),
49+
ClientInterface::class => new InvokableFactory(
50+
Psr18Client::class,
51+
HttpClient::class,
52+
ResponseFactoryInterface::class,
53+
StreamFactoryInterface::class,
54+
),
55+
];
56+
}
57+
58+
/**
59+
* Retrieves an array of service extensions.
60+
*
61+
* This method MUST return an associative array of callables to extend existing services.
62+
* If no extensions are to be registered, an empty array MUST be returned.
63+
*
64+
* @return array<class-string, callable> an associative array of service extensions
65+
*/
66+
public function getExtensions(): array
67+
{
68+
return [];
69+
}
70+
}

0 commit comments

Comments
 (0)