|
| 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 | +} |
0 commit comments