| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClientDependencies\Nyholm\Psr7\Factory; 5 6 use WordPress\AiClientDependencies\Nyholm\Psr7\Request; 7 use WordPress\AiClientDependencies\Nyholm\Psr7\Response; 8 use WordPress\AiClientDependencies\Nyholm\Psr7\ServerRequest; 9 use WordPress\AiClientDependencies\Nyholm\Psr7\Stream; 10 use WordPress\AiClientDependencies\Nyholm\Psr7\UploadedFile; 11 use WordPress\AiClientDependencies\Nyholm\Psr7\Uri; 12 use WordPress\AiClientDependencies\Psr\Http\Message\RequestFactoryInterface; 13 use WordPress\AiClientDependencies\Psr\Http\Message\RequestInterface; 14 use WordPress\AiClientDependencies\Psr\Http\Message\ResponseFactoryInterface; 15 use WordPress\AiClientDependencies\Psr\Http\Message\ResponseInterface; 16 use WordPress\AiClientDependencies\Psr\Http\Message\ServerRequestFactoryInterface; 17 use WordPress\AiClientDependencies\Psr\Http\Message\ServerRequestInterface; 18 use WordPress\AiClientDependencies\Psr\Http\Message\StreamFactoryInterface; 19 use WordPress\AiClientDependencies\Psr\Http\Message\StreamInterface; 20 use WordPress\AiClientDependencies\Psr\Http\Message\UploadedFileFactoryInterface; 21 use WordPress\AiClientDependencies\Psr\Http\Message\UploadedFileInterface; 22 use WordPress\AiClientDependencies\Psr\Http\Message\UriFactoryInterface; 23 use WordPress\AiClientDependencies\Psr\Http\Message\UriInterface; 24 /** 25 * @author Tobias Nyholm <tobias.nyholm@gmail.com> 26 * @author Martijn van der Ven <martijn@vanderven.se> 27 * 28 * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md 29 */ 30 class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface 31 { 32 public function createRequest(string $method, $uri): RequestInterface 33 { 34 return new Request($method, $uri); 35 } 36 public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface 37 { 38 if (2 > \func_num_args()) { 39 // This will make the Response class to use a custom reasonPhrase 40 $reasonPhrase = null; 41 } 42 return new Response($code, [], null, '1.1', $reasonPhrase); 43 } 44 public function createStream(string $content = ''): StreamInterface 45 { 46 return Stream::create($content); 47 } 48 public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface 49 { 50 if ('' === $filename) { 51 throw new \RuntimeException('Path cannot be empty'); 52 } 53 if (\false === $resource = @\fopen($filename, $mode)) { 54 if ('' === $mode || \false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], \true)) { 55 throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode)); 56 } 57 throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? '')); 58 } 59 return Stream::create($resource); 60 } 61 public function createStreamFromResource($resource): StreamInterface 62 { 63 return Stream::create($resource); 64 } 65 public function createUploadedFile(StreamInterface $stream, ?int $size = null, int $error = \UPLOAD_ERR_OK, ?string $clientFilename = null, ?string $clientMediaType = null): UploadedFileInterface 66 { 67 if (null === $size) { 68 $size = $stream->getSize(); 69 } 70 return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); 71 } 72 public function createUri(string $uri = ''): UriInterface 73 { 74 return new Uri($uri); 75 } 76 public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface 77 { 78 return new ServerRequest($method, $uri, [], null, '1.1', $serverParams); 79 } 80 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |