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