PluginProbe
Authorizer / 3.6.0
Authorizer v3.6.0
3.16.0 3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 All 127 releases
authorizer / vendor / guzzlehttp / psr7 / src / HttpFactory.php

HttpFactory.php in Authorizer 3.6.0, at vendor/guzzlehttp/psr7/src/HttpFactory.php

101 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace GuzzleHttp\Psr7;
6
7 use Psr\Http\Message\RequestFactoryInterface;
8 use Psr\Http\Message\RequestInterface;
9 use Psr\Http\Message\ResponseFactoryInterface;
10 use Psr\Http\Message\ResponseInterface;
11 use Psr\Http\Message\ServerRequestFactoryInterface;
12 use Psr\Http\Message\ServerRequestInterface;
13 use Psr\Http\Message\StreamFactoryInterface;
14 use Psr\Http\Message\StreamInterface;
15 use Psr\Http\Message\UploadedFileFactoryInterface;
16 use Psr\Http\Message\UploadedFileInterface;
17 use Psr\Http\Message\UriFactoryInterface;
18 use Psr\Http\Message\UriInterface;
19
20 /**
21 * Implements all of the PSR-17 interfaces.
22 *
23 * Note: in consuming code it is recommended to require the implemented interfaces
24 * and inject the instance of this class multiple times.
25 */
26 final class HttpFactory implements
27 RequestFactoryInterface,
28 ResponseFactoryInterface,
29 ServerRequestFactoryInterface,
30 StreamFactoryInterface,
31 UploadedFileFactoryInterface,
32 UriFactoryInterface
33 {
34 public function createUploadedFile(
35 StreamInterface $stream,
36 int $size = null,
37 int $error = \UPLOAD_ERR_OK,
38 string $clientFilename = null,
39 string $clientMediaType = null
40 ): UploadedFileInterface {
41 if ($size === null) {
42 $size = $stream->getSize();
43 }
44
45 return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
46 }
47
48 public function createStream(string $content = ''): StreamInterface
49 {
50 return Utils::streamFor($content);
51 }
52
53 public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
54 {
55 try {
56 $resource = Utils::tryFopen($file, $mode);
57 } catch (\RuntimeException $e) {
58 if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) {
59 throw new \InvalidArgumentException(sprintf('Invalid file opening mode "%s"', $mode), 0, $e);
60 }
61
62 throw $e;
63 }
64
65 return Utils::streamFor($resource);
66 }
67
68 public function createStreamFromResource($resource): StreamInterface
69 {
70 return Utils::streamFor($resource);
71 }
72
73 public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
74 {
75 if (empty($method)) {
76 if (!empty($serverParams['REQUEST_METHOD'])) {
77 $method = $serverParams['REQUEST_METHOD'];
78 } else {
79 throw new \InvalidArgumentException('Cannot determine HTTP method');
80 }
81 }
82
83 return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
84 }
85
86 public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
87 {
88 return new Response($code, [], null, '1.1', $reasonPhrase);
89 }
90
91 public function createRequest(string $method, $uri): RequestInterface
92 {
93 return new Request($method, $uri);
94 }
95
96 public function createUri(string $uri = ''): UriInterface
97 {
98 return new Uri($uri);
99 }
100 }
101