Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HttpClientServiceProvider
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 getFactories
100.00% covered (success)
100.00%
9 / 9
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-client.
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-client
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Http\Client\ServiceProvider;
20
21use FastForward\Container\Factory\InvokableFactory;
22use FastForward\Container\Factory\MethodFactory;
23use Interop\Container\ServiceProviderInterface;
24use Psr\Http\Client\ClientInterface;
25use Psr\Http\Message\ResponseFactoryInterface;
26use Psr\Http\Message\StreamFactoryInterface;
27use Symfony\Component\HttpClient\HttpClient;
28use Symfony\Component\HttpClient\Psr18Client;
29
30/**
31 * Class HttpClientServiceProvider.
32 *
33 * Provides a PSR-compliant HTTP client service provider for dependency injection containers.
34 * This service provider SHALL register factories for HTTP client services.
35 * It MUST implement the ServiceProviderInterface to allow standardized service registration.
36 */
37 class HttpClientServiceProvider implements ServiceProviderInterface
38{
39    /**
40     * Retrieves an array of service factories.
41     *
42     * This method MUST return an associative array where the key is the service name or interface
43     * and the value is a callable or factory responsible for creating the service.
44     * The array returned SHALL register the default Symfony HttpClient and a PSR-18 compatible client.
45     *
46     * @return array<class-string, callable> an associative array of service factories
47     */
48    public function getFactories(): array
49    {
50        return [
51            HttpClient::class      => new MethodFactory(HttpClient::class, 'create'),
52            ClientInterface::class => new InvokableFactory(
53                Psr18Client::class,
54                HttpClient::class,
55                ResponseFactoryInterface::class,
56                StreamFactoryInterface::class,
57            ),
58        ];
59    }
60
61    /**
62     * Retrieves an array of service extensions.
63     *
64     * This method MUST return an associative array of callables to extend existing services.
65     * If no extensions are to be registered, an empty array MUST be returned.
66     *
67     * @return array<class-string, callable> an associative array of service extensions
68     */
69    public function getExtensions(): array
70    {
71        return [];
72    }
73}