Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
HttpClientServiceProvider | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
getFactories | |
100.00% |
9 / 9 |
|
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-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 | } |