PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.1.17
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.1.17
4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 All 173 releases
searchpro / BerqWP / vendor / guzzlehttp / psr7 / src / HttpFactory.php

HttpFactory.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.1.17, at BerqWP/vendor/guzzlehttp/psr7/src/HttpFactory.php

95 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 RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
27 {
28 public function createUploadedFile(
29 StreamInterface $stream,
30 ?int $size = null,
31 int $error = \UPLOAD_ERR_OK,
32 ?string $clientFilename = null,
33 ?string $clientMediaType = null
34 ): UploadedFileInterface {
35 if ($size === null) {
36 $size = $stream->getSize();
37 }
38
39 return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
40 }
41
42 public function createStream(string $content = ''): StreamInterface
43 {
44 return Utils::streamFor($content);
45 }
46
47 public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
48 {
49 try {
50 $resource = Utils::tryFopen($file, $mode);
51 } catch (\RuntimeException $e) {
52 if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) {
53 throw new \InvalidArgumentException(sprintf('Invalid file opening mode "%s"', $mode), 0, $e);
54 }
55
56 throw $e;
57 }
58
59 return Utils::streamFor($resource);
60 }
61
62 public function createStreamFromResource($resource): StreamInterface
63 {
64 return Utils::streamFor($resource);
65 }
66
67 public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
68 {
69 if (empty($method)) {
70 if (!empty($serverParams['REQUEST_METHOD'])) {
71 $method = $serverParams['REQUEST_METHOD'];
72 } else {
73 throw new \InvalidArgumentException('Cannot determine HTTP method');
74 }
75 }
76
77 return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
78 }
79
80 public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
81 {
82 return new Response($code, [], null, '1.1', $reasonPhrase);
83 }
84
85 public function createRequest(string $method, $uri): RequestInterface
86 {
87 return new Request($method, $uri);
88 }
89
90 public function createUri(string $uri = ''): UriInterface
91 {
92 return new Uri($uri);
93 }
94 }
95