Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\ServerRequestInterface;
14
use RuntimeException;
15
use Slim\Interfaces\ServerRequestCreatorInterface;
16
 
17
use function class_exists;
18
 
19
class SlimHttpServerRequestCreator implements ServerRequestCreatorInterface
20
{
21
    protected ServerRequestCreatorInterface $serverRequestCreator;
22
 
23
    protected static string $serverRequestDecoratorClass = 'Slim\Http\ServerRequest';
24
 
25
    public function __construct(ServerRequestCreatorInterface $serverRequestCreator)
26
    {
27
        $this->serverRequestCreator = $serverRequestCreator;
28
    }
29
 
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function createServerRequestFromGlobals(): ServerRequestInterface
34
    {
35
        if (!static::isServerRequestDecoratorAvailable()) {
36
            throw new RuntimeException('The Slim-Http ServerRequest decorator is not available.');
37
        }
38
 
39
        $request = $this->serverRequestCreator->createServerRequestFromGlobals();
40
 
41
        if (
42
            !((
43
                $decoratedServerRequest = new static::$serverRequestDecoratorClass($request)
44
                ) instanceof ServerRequestInterface)
45
        ) {
46
            throw new RuntimeException(get_called_class() . ' could not instantiate a decorated server request.');
47
        }
48
 
49
        return $decoratedServerRequest;
50
    }
51
 
52
    public static function isServerRequestDecoratorAvailable(): bool
53
    {
54
        return class_exists(static::$serverRequestDecoratorClass);
55
    }
56
}