Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
32 / 32 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
HttpMessageFactoryServiceProvider | |
100.00% |
32 / 32 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
getFactories | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
1 | |||
getExtensions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 | use FastForward\Container\Factory\AliasFactory; |
19 | use FastForward\Container\Factory\InvokableFactory; |
20 | use FastForward\Container\Factory\MethodFactory; |
21 | use FastForward\Http\Message\Factory\ResponseFactory; |
22 | use FastForward\Http\Message\Factory\ResponseFactoryInterface; |
23 | use FastForward\Http\Message\Factory\StreamFactory; |
24 | use FastForward\Http\Message\Factory\StreamFactoryInterface; |
25 | use Interop\Container\ServiceProviderInterface; |
26 | use Nyholm\Psr7\Factory\Psr17Factory; |
27 | use Nyholm\Psr7Server\ServerRequestCreator; |
28 | use Nyholm\Psr7Server\ServerRequestCreatorInterface; |
29 | use Psr\Http\Message\RequestFactoryInterface; |
30 | use Psr\Http\Message\ResponseFactoryInterface as PsrResponseFactoryInterface; |
31 | use Psr\Http\Message\ServerRequestFactoryInterface; |
32 | use Psr\Http\Message\ServerRequestInterface; |
33 | use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface; |
34 | use Psr\Http\Message\UploadedFileFactoryInterface; |
35 | use Psr\Http\Message\UriFactoryInterface; |
36 | |
37 | /** |
38 | * This file is part of php-fast-forward/http-factory. |
39 | * |
40 | * This source file is subject to the license bundled |
41 | * with this source code in the file LICENSE. |
42 | * |
43 | * @see https://github.com/php-fast-forward/http-factory |
44 | * |
45 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
46 | * @license https://opensource.org/licenses/MIT MIT License |
47 | */ |
48 | final class HttpMessageFactoryServiceProvider implements ServiceProviderInterface |
49 | { |
50 | /** |
51 | * Returns a list of service factories compliant with PSR-11. |
52 | * |
53 | * This method defines mappings for PSR-17 and PSR-7 related interfaces |
54 | * using Nyholm's implementation. Aliases are created for consistency |
55 | * across PSR interfaces by reusing a single Psr17Factory instance. |
56 | * |
57 | * @return array<string, callable> an associative array of service identifiers to factory definitions |
58 | */ |
59 | public function getFactories(): array |
60 | { |
61 | return [ |
62 | RequestFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
63 | PsrResponseFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
64 | ServerRequestFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
65 | PsrStreamFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
66 | UploadedFileFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
67 | UriFactoryInterface::class => AliasFactory::get(Psr17Factory::class), |
68 | ServerRequestCreatorInterface::class => AliasFactory::get(ServerRequestCreator::class), |
69 | ResponseFactoryInterface::class => AliasFactory::get(ResponseFactory::class), |
70 | StreamFactoryInterface::class => AliasFactory::get(StreamFactory::class), |
71 | Psr17Factory::class => new InvokableFactory(Psr17Factory::class), |
72 | ServerRequestCreator::class => new InvokableFactory( |
73 | ServerRequestCreator::class, |
74 | RequestFactoryInterface::class, |
75 | UriFactoryInterface::class, |
76 | UploadedFileFactoryInterface::class, |
77 | StreamFactoryInterface::class, |
78 | ), |
79 | ResponseFactory::class => new InvokableFactory( |
80 | ResponseFactory::class, |
81 | PsrResponseFactoryInterface::class, |
82 | ), |
83 | StreamFactory::class => new InvokableFactory( |
84 | StreamFactory::class, |
85 | PsrStreamFactoryInterface::class, |
86 | ), |
87 | ServerRequestInterface::class => new MethodFactory( |
88 | ServerRequestCreator::class, |
89 | 'fromGlobals' |
90 | ), |
91 | ]; |
92 | } |
93 | |
94 | /** |
95 | * Returns an array of service extensions. |
96 | * |
97 | * This service provider does not define extensions and SHALL return an empty array. |
98 | * |
99 | * @return array<string, callable> an empty array |
100 | */ |
101 | public function getExtensions(): array |
102 | { |
103 | return []; |
104 | } |
105 | } |