@@ -19,10 +19,13 @@ Alternatively, you can clone the `<https://github.com/symfony/psr-http-message-b
19
19
20
20
.. include :: /components/require_autoload.rst.inc
21
21
22
- The bridge also needs a PSR-7 implementation to allow converting HttpFoundation
23
- objects to PSR-7 objects. It provides native support for `Zend Diactoros `_.
24
- Use Composer (`zendframework/zend-diactoros on Packagist <https://packagist.org/packages/zendframework/zend-diactoros >`_)
25
- or refer to the project documentation to install it.
22
+ The bridge also needs a PSR-7 and `PSR-17 `_ implementation to allow converting
23
+ HttpFoundation objects to PSR-7 objects. See a full list of PSR-17 libraries on
24
+ that provide `psr/http-factory-implementation `_ on Packagist.org. Example:
25
+
26
+ .. code-block :: terminal
27
+
28
+ $ composer require nyholm/psr7
26
29
27
30
Usage
28
31
-----
@@ -33,32 +36,35 @@ Converting from HttpFoundation Objects to PSR-7
33
36
The bridge provides an interface of a factory called
34
37
:class: `Symfony\\ Bridge\\ PsrHttpMessage\\ HttpMessageFactoryInterface `
35
38
that builds objects implementing PSR-7 interfaces from HttpFoundation objects.
36
- It also provide a default implementation using Zend Diactoros internally.
37
39
38
40
The following code snippet explains how to convert a :class: `Symfony\\ Component\\ HttpFoundation\\ Request `
39
- to a ``Zend\Diactoros \ServerRequest `` class implementing the
41
+ to a ``Nyholm\Psr7 \ServerRequest `` class implementing the
40
42
``Psr\Http\Message\ServerRequestInterface `` interface::
41
43
42
- use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
44
+ use Nyholm\Psr7\Factory\Psr17Factory;
45
+ use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
43
46
use Symfony\Component\HttpFoundation\Request;
44
47
45
48
$symfonyRequest = new Request([], [], [], [], [], ['HTTP_HOST' => 'dunglas.fr'], 'Content');
46
49
// The HTTP_HOST server key must be set to avoid an unexpected error
47
50
48
- $psr7Factory = new DiactorosFactory();
49
- $psrRequest = $psr7Factory->createRequest($symfonyRequest);
51
+ $psr17Factory = new Psr17Factory();
52
+ $psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
53
+ $psrRequest = $psrHttpFactory->createRequest($symfonyRequest);
50
54
51
55
And now from a :class: `Symfony\\ Component\\ HttpFoundation\\ Response ` to a
52
- ``Zend\Diactoros \Response `` class implementing the
56
+ ``Nyholm\Psr7 \Response `` class implementing the
53
57
``Psr\Http\Message\ResponseInterface `` interface::
54
58
55
- use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
59
+ use Nyholm\Psr7\Factory\Psr17Factory;
60
+ use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
56
61
use Symfony\Component\HttpFoundation\Response;
57
62
58
63
$symfonyResponse = new Response('Content');
59
64
60
- $psr7Factory = new DiactorosFactory();
61
- $psrResponse = $psr7Factory->createResponse($symfonyResponse);
65
+ $psr17Factory = new Psr17Factory();
66
+ $psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
67
+ $psrResponse = $psrHttpFactory->createResponse($symfonyResponse);
62
68
63
69
Converting Objects implementing PSR-7 Interfaces to HttpFoundation
64
70
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -89,5 +95,6 @@ to a :class:`Symfony\\Component\\HttpFoundation\\Response` instance::
89
95
$symfonyResponse = $httpFoundationFactory->createResponse($psrResponse);
90
96
91
97
.. _`PSR-7` : https://www.php-fig.org/psr/psr-7/
92
- .. _`Zend Diactoros` : https://github.com/zendframework/zend-diactoros
98
+ .. _`PSR-17` : https://www.php-fig.org/psr/psr-17/
99
+ .. _`psr/http-factory-implementation` : https://packagist.org/providers/psr/http-factory-implementation
93
100
.. _`symfony/psr-http-message-bridge on Packagist` : https://packagist.org/packages/symfony/psr-http-message-bridge
0 commit comments