Title: Psr17Factory
Published: May 20, 2026
Last modified: August 20, 2026

---

# class Psr17Factory {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/?output_format=md#source)

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/?output_format=md#methods)󠁿

| Name | Description | 
| [Psr17Factory::createRequest](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createrequest/) | – | 
| [Psr17Factory::createResponse](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createresponse/) | – | 
| [Psr17Factory::createServerRequest](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createserverrequest/) | – | 
| [Psr17Factory::createStream](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createstream/) | – | 
| [Psr17Factory::createStreamFromFile](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createstreamfromfile/) | – | 
| [Psr17Factory::createStreamFromResource](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createstreamfromresource/) | – | 
| [Psr17Factory::createUploadedFile](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createuploadedfile/) | – | 
| [Psr17Factory::createUri](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/createuri/) | – |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory/?output_format=md#source)󠁿

    ```php
    class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
    {
        public function createRequest(string $method, $uri): RequestInterface
        {
            return new Request($method, $uri);
        }
        public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
        {
            if (2 > \func_num_args()) {
                // This will make the Response class to use a custom reasonPhrase
                $reasonPhrase = null;
            }
            return new Response($code, [], null, '1.1', $reasonPhrase);
        }
        public function createStream(string $content = ''): StreamInterface
        {
            return Stream::create($content);
        }
        public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
        {
            if ('' === $filename) {
                throw new \RuntimeException('Path cannot be empty');
            }
            if (\false === $resource = @\fopen($filename, $mode)) {
                if ('' === $mode || \false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], \true)) {
                    throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode));
                }
                throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? ''));
            }
            return Stream::create($resource);
        }
        public function createStreamFromResource($resource): StreamInterface
        {
            return Stream::create($resource);
        }
        public function createUploadedFile(StreamInterface $stream, ?int $size = null, int $error = \UPLOAD_ERR_OK, ?string $clientFilename = null, ?string $clientMediaType = null): UploadedFileInterface
        {
            if (null === $size) {
                $size = $stream->getSize();
            }
            return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
        }
        public function createUri(string $uri = ''): UriInterface
        {
            return new Uri($uri);
        }
        public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
        {
            return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
        }
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/third-party/nyholm/psr7/factory/psr17factory.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Factory/Psr17Factory.php#L30)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Factory/Psr17Factory.php#L30-L80)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclientdependencies-nyholm-psr7-factory-psr17factory%2F)
before being able to contribute a note or feedback.