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