Skip to content

Commit 42c0e64

Browse files
committed
First commit!
0 parents  commit 42c0e64

File tree

10 files changed

+354
-0
lines changed

10 files changed

+354
-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-factory.
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-factory
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

.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-factory.
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-factory
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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "fast-forward/http-factory",
3+
"description": "Fast Forward PSR-7 HTTP Factory utility classes",
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-factory/issues",
15+
"source": "https://github.com/php-fast-forward/http-factory"
16+
},
17+
"require": {
18+
"php": "^8.1",
19+
"container-interop/service-provider": "^0.4.1",
20+
"fast-forward/container": "^1.2",
21+
"nyholm/psr7": "^1.8",
22+
"nyholm/psr7-server": "^1.1",
23+
"psr/http-factory": "^1.1",
24+
"psr/http-message": "^2.0"
25+
},
26+
"require-dev": {
27+
"coisa/php-cs-fixer": "^2.1",
28+
"phpspec/prophecy-phpunit": "^2.3",
29+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5"
30+
},
31+
"minimum-stability": "stable",
32+
"autoload": {
33+
"psr-4": {
34+
"FastForward\\Http\\Message\\Factory\\": "src/"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"FastForward\\Http\\Message\\Factory\\Tests\\": "tests/"
40+
}
41+
},
42+
"config": {
43+
"sort-packages": true
44+
},
45+
"extra": {
46+
"branch-alias": {
47+
"dev-main": "1.x-dev"
48+
}
49+
},
50+
"scripts": {
51+
"cs-check": "php-cs-fixer fix --dry-run --diff",
52+
"cs-fix": "php-cs-fixer fix",
53+
"mutation-testing": "infection --threads=4",
54+
"pre-commit": [
55+
"@cs-check",
56+
"@static-analysis",
57+
"@tests"
58+
],
59+
"static-analysis": "phpstan analyse --level 5 src",
60+
"tests": "phpunit --testdox"
61+
}
62+
}

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 Config 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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-factory.
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-factory
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\Message\Factory\ServiceProvider;
17+
18+
/*
19+
* This file is part of php-fast-forward/http-factory.
20+
*
21+
* This source file is subject to the license bundled
22+
* with this source code in the file LICENSE.
23+
*
24+
* @link https://github.com/php-fast-forward/http-factory
25+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
26+
* @license https://opensource.org/licenses/MIT MIT License
27+
*/
28+
29+
use FastForward\Container\Factory\AliasFactory;
30+
use FastForward\Container\Factory\InvokableFactory;
31+
use FastForward\Container\Factory\MethodFactory;
32+
use Interop\Container\ServiceProviderInterface;
33+
use Nyholm\Psr7\Factory\Psr17Factory;
34+
use Nyholm\Psr7Server\ServerRequestCreator;
35+
use Psr\Http\Message\RequestFactoryInterface;
36+
use Psr\Http\Message\ResponseFactoryInterface;
37+
use Psr\Http\Message\ServerRequestFactoryInterface;
38+
use Psr\Http\Message\ServerRequestInterface;
39+
use Psr\Http\Message\StreamFactoryInterface;
40+
use Psr\Http\Message\UploadedFileFactoryInterface;
41+
use Psr\Http\Message\UriFactoryInterface;
42+
43+
/**
44+
* This file is part of php-fast-forward/http-factory.
45+
*
46+
* This source file is subject to the license bundled
47+
* with this source code in the file LICENSE.
48+
*
49+
* @see https://github.com/php-fast-forward/http-factory
50+
*
51+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
52+
* @license https://opensource.org/licenses/MIT MIT License
53+
*/
54+
final class HttpMessageFactoryServiceProvider implements ServiceProviderInterface
55+
{
56+
/**
57+
* Returns a list of service factories compliant with PSR-11.
58+
*
59+
* This method defines mappings for PSR-17 and PSR-7 related interfaces
60+
* using Nyholm's implementation. Aliases are created for consistency
61+
* across PSR interfaces by reusing a single Psr17Factory instance.
62+
*
63+
* @return array<string, callable> an associative array of service identifiers to factory definitions
64+
*/
65+
public function getFactories(): array
66+
{
67+
return [
68+
Psr17Factory::class => new InvokableFactory(Psr17Factory::class),
69+
ServerRequestCreator::class => new InvokableFactory(
70+
ServerRequestCreator::class,
71+
RequestFactoryInterface::class,
72+
UriFactoryInterface::class,
73+
UploadedFileFactoryInterface::class,
74+
StreamFactoryInterface::class,
75+
),
76+
ServerRequestInterface::class => new MethodFactory(
77+
ServerRequestCreator::class,
78+
'fromGlobals'
79+
),
80+
RequestFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
81+
ResponseFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
82+
ServerRequestFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
83+
StreamFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
84+
UploadedFileFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
85+
UriFactoryInterface::class => AliasFactory::get(Psr17Factory::class),
86+
];
87+
}
88+
89+
/**
90+
* Returns an array of service extensions.
91+
*
92+
* This service provider does not define extensions and SHALL return an empty array.
93+
*
94+
* @return array<string, callable> an empty array
95+
*/
96+
public function getExtensions(): array
97+
{
98+
return [];
99+
}
100+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-factory.
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-factory
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\Message\Factory\Tests\ServiceProvider;
17+
18+
use FastForward\Container\Factory\AliasFactory;
19+
use FastForward\Container\Factory\InvokableFactory;
20+
use FastForward\Container\Factory\MethodFactory;
21+
use FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider;
22+
use Nyholm\Psr7\Factory\Psr17Factory;
23+
use Nyholm\Psr7Server\ServerRequestCreator;
24+
use PHPUnit\Framework\Attributes\CoversClass;
25+
use PHPUnit\Framework\TestCase;
26+
use Psr\Http\Message\RequestFactoryInterface;
27+
use Psr\Http\Message\ResponseFactoryInterface;
28+
use Psr\Http\Message\ServerRequestFactoryInterface;
29+
use Psr\Http\Message\ServerRequestInterface;
30+
use Psr\Http\Message\StreamFactoryInterface;
31+
use Psr\Http\Message\UploadedFileFactoryInterface;
32+
use Psr\Http\Message\UriFactoryInterface;
33+
34+
/**
35+
* @internal
36+
*/
37+
#[CoversClass(HttpMessageFactoryServiceProvider::class)]
38+
final class HttpMessageFactoryServiceProviderTest extends TestCase
39+
{
40+
public function testGetFactoriesReturnsExpectedMappings(): void
41+
{
42+
$provider = new HttpMessageFactoryServiceProvider();
43+
$factories = $provider->getFactories();
44+
45+
self::assertArrayHasKey(Psr17Factory::class, $factories);
46+
self::assertInstanceOf(InvokableFactory::class, $factories[Psr17Factory::class]);
47+
48+
self::assertArrayHasKey(ServerRequestCreator::class, $factories);
49+
self::assertInstanceOf(InvokableFactory::class, $factories[ServerRequestCreator::class]);
50+
51+
self::assertArrayHasKey(ServerRequestInterface::class, $factories);
52+
self::assertInstanceOf(MethodFactory::class, $factories[ServerRequestInterface::class]);
53+
54+
$aliases = [
55+
RequestFactoryInterface::class,
56+
ResponseFactoryInterface::class,
57+
ServerRequestFactoryInterface::class,
58+
StreamFactoryInterface::class,
59+
UploadedFileFactoryInterface::class,
60+
UriFactoryInterface::class,
61+
];
62+
63+
foreach ($aliases as $alias) {
64+
self::assertArrayHasKey($alias, $factories);
65+
self::assertInstanceOf(AliasFactory::class, $factories[$alias]);
66+
}
67+
}
68+
69+
public function testGetExtensionsReturnsEmptyArray(): void
70+
{
71+
$provider = new HttpMessageFactoryServiceProvider();
72+
self::assertSame([], $provider->getExtensions());
73+
}
74+
}

0 commit comments

Comments
 (0)