Completed
Push — master ( 93a9b6...fec7c1 )
by Tobias
02:09
created

Psr17Factory::createServerRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7\Factory;
6
7
use Nyholm\Psr7\Request;
8
use Nyholm\Psr7\Response;
9
use Nyholm\Psr7\ServerRequest;
10
use Nyholm\Psr7\Stream;
11
use Nyholm\Psr7\UploadedFile;
12
use Nyholm\Psr7\Uri;
13
use Psr\Http\Message\RequestFactoryInterface;
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Http\Message\ResponseFactoryInterface;
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestFactoryInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Psr\Http\Message\StreamFactoryInterface;
20
use Psr\Http\Message\StreamInterface;
21
use Psr\Http\Message\UploadedFileFactoryInterface;
22
use Psr\Http\Message\UploadedFileInterface;
23
use Psr\Http\Message\UriFactoryInterface;
24
use Psr\Http\Message\UriInterface;
25
26
/**
27
 * @author Tobias Nyholm <[email protected]>
28
 * @author Martijn van der Ven <[email protected]>
29
 */
30
final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
31
{
32 7
    public function createRequest(string $method, $uri): RequestInterface
33
    {
34 7
        return new Request($method, $uri);
35
    }
36
37 4
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
38
    {
39 4
        return new Response($code, [], null, '1.1', $reasonPhrase);
40
    }
41
42 6
    public function createStream(string $content = ''): StreamInterface
43
    {
44 6
        return Stream::create($content);
45
    }
46
47 1
    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
48
    {
49 1
        return Stream::createFromResource(fopen($filename, $mode));
50
    }
51
52 1
    public function createStreamFromResource($resource): StreamInterface
53
    {
54 1
        return Stream::createFromResource($resource);
55
    }
56
57 12
    public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
58
    {
59 12
        if (null === $size) {
60 12
            $size = $stream->getSize();
61
        }
62
63 12
        return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
64
    }
65
66 13
    public function createUri(string $uri = ''): UriInterface
67
    {
68 13
        return new Uri($uri);
69
    }
70
71 23
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
72
    {
73 23
        return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
74
    }
75
}
76