1+ <?php
2+
3+ namespace Prokl \ServiceProvider \Services \PSR \PSR17 ;
4+
5+ use GuzzleHttp \Psr7 \Request ;
6+ use GuzzleHttp \Psr7 \Response ;
7+ use GuzzleHttp \Psr7 \ServerRequest ;
8+ use GuzzleHttp \Psr7 \UploadedFile ;
9+ use GuzzleHttp \Psr7 \Uri ;
10+ use GuzzleHttp \Psr7 \Utils ;
11+ use Psr \Http \Message \RequestFactoryInterface ;
12+ use Psr \Http \Message \RequestInterface ;
13+ use Psr \Http \Message \ResponseFactoryInterface ;
14+ use Psr \Http \Message \ResponseInterface ;
15+ use Psr \Http \Message \ServerRequestFactoryInterface ;
16+ use Psr \Http \Message \ServerRequestInterface ;
17+ use Psr \Http \Message \StreamFactoryInterface ;
18+ use Psr \Http \Message \StreamInterface ;
19+ use Psr \Http \Message \UploadedFileFactoryInterface ;
20+ use Psr \Http \Message \UploadedFileInterface ;
21+ use Psr \Http \Message \UriFactoryInterface ;
22+ use Psr \Http \Message \UriInterface ;
23+
24+ /**
25+ * Class HttpFactory
26+ * @package Prokl\ServiceProvider\Services\PSR\PSR17
27+ */
28+ class HttpFactory implements
29+ RequestFactoryInterface,
30+ ResponseFactoryInterface,
31+ ServerRequestFactoryInterface,
32+ StreamFactoryInterface,
33+ UploadedFileFactoryInterface,
34+ UriFactoryInterface
35+ {
36+ /**
37+ * @inheritDoc
38+ */
39+ public function createRequest (string $ method , $ uri ): RequestInterface
40+ {
41+ return new Request ($ method , $ uri );
42+ }
43+
44+ /**
45+ * @inheritDoc
46+ */
47+ public function createResponse (int $ code = 200 , string $ reasonPhrase = '' ): ResponseInterface
48+ {
49+ return new Response ($ code , [], null , '1.1 ' , $ reasonPhrase );
50+ }
51+
52+ /**
53+ * @inheritDoc
54+ */
55+ public function createServerRequest (string $ method , $ uri , array $ serverParams = []): ServerRequestInterface
56+ {
57+ return new ServerRequest ($ method , $ uri , [], null , '1.1 ' , $ serverParams );
58+ }
59+
60+ /**
61+ * @inheritDoc
62+ */
63+ public function createStream (string $ content = '' ): StreamInterface
64+ {
65+ return Utils::streamFor ($ content );
66+ }
67+
68+ /**
69+ * @inheritDoc
70+ */
71+ public function createStreamFromFile (string $ filename , string $ mode = 'r ' ): StreamInterface
72+ {
73+ return Utils::streamFor (fopen ($ filename , $ mode ));
74+ }
75+
76+ /**
77+ * @inheritDoc
78+ */
79+ public function createStreamFromResource ($ resource ): StreamInterface
80+ {
81+ return Utils::streamFor ($ resource );
82+ }
83+
84+ /**
85+ * @inheritDoc
86+ */
87+ public function createUploadedFile (
88+ StreamInterface $ stream ,
89+ int $ size = null ,
90+ int $ error = \UPLOAD_ERR_OK ,
91+ string $ clientFilename = null ,
92+ string $ clientMediaType = null
93+ ): UploadedFileInterface
94+ {
95+ return new UploadedFile ($ stream , $ size , $ error , $ clientFilename , $ clientMediaType );
96+ }
97+
98+ /**
99+ * @inheritDoc
100+ */
101+ public function createUri (string $ uri = '' ): UriInterface
102+ {
103+ return new Uri ($ uri );
104+ }
105+ }
0 commit comments