Debian Codegraph @

lib/3rdParty/composer/nyholm/psr7/src/Factory/HttplugFactory.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Nyholm\Psr7\Factory;
6
7 use Http\Message\{MessageFactory, StreamFactory, UriFactory};
8 use Nyholm\Psr7\{Request, Response, Stream, Uri};
9 use Psr\Http\Message\RequestInterface;
10 use Psr\Http\Message\ResponseInterface;
11 use Psr\Http\Message\StreamInterface;
12 use Psr\Http\Message\UriInterface;
13
14 if (!\interface_exists(MessageFactory::class)) {
15 throw new \LogicException('You cannot use "Nyholm\Psr7\Factory\HttplugFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
16 }
17
18 @\trigger_error('Class "Nyholm\Psr7\Factory\HttplugFactory" is deprecated since version 1.8, use "Nyholm\Psr7\Factory\Psr17Factory" instead.', \E_USER_DEPRECATED);
19
20 /**
21 * @author Tobias Nyholm <[email protected]>
22 * @author Martijn van der Ven <[email protected]>
23 *
24 * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
25 *
26 * @deprecated since version 1.8, use Psr17Factory instead
27 */
28 class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
29 {
30 public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1'): RequestInterface
31 {
32 return new Request($method, $uri, $headers, $body, $protocolVersion);
33 }
34
35 public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1'): ResponseInterface
36 {
37 return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
38 }
39
40 public function createStream($body = null): StreamInterface
41 {
42 return Stream::create($body ?? '');
43 }
44
45 public function createUri($uri = ''): UriInterface
46 {
47 if ($uri instanceof UriInterface) {
48 return $uri;
49 }
50
51 return new Uri($uri);
52 }
53 }