| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Slim Framework (https://slimframework.com)
|
|
|
5 |
*
|
|
|
6 |
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
declare(strict_types=1);
|
|
|
10 |
|
|
|
11 |
namespace Slim\Factory\Psr17;
|
|
|
12 |
|
|
|
13 |
use Psr\Http\Message\ResponseFactoryInterface;
|
|
|
14 |
use Psr\Http\Message\StreamFactoryInterface;
|
|
|
15 |
use RuntimeException;
|
|
|
16 |
|
|
|
17 |
class SlimHttpPsr17Factory extends Psr17Factory
|
|
|
18 |
{
|
|
|
19 |
protected static string $responseFactoryClass = 'Slim\Http\Factory\DecoratedResponseFactory';
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @throws RuntimeException when the factory could not be instantiated
|
|
|
23 |
*/
|
|
|
24 |
public static function createDecoratedResponseFactory(
|
|
|
25 |
ResponseFactoryInterface $responseFactory,
|
|
|
26 |
StreamFactoryInterface $streamFactory
|
|
|
27 |
): ResponseFactoryInterface {
|
|
|
28 |
if (
|
|
|
29 |
!((
|
|
|
30 |
$decoratedResponseFactory = new static::$responseFactoryClass($responseFactory, $streamFactory)
|
|
|
31 |
) instanceof ResponseFactoryInterface
|
|
|
32 |
)
|
|
|
33 |
) {
|
|
|
34 |
throw new RuntimeException(get_called_class() . ' could not instantiate a decorated response factory.');
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
return $decoratedResponseFactory;
|
|
|
38 |
}
|
|
|
39 |
}
|