Skip to content

Commit 0a08c07

Browse files
Nyholmdbu
authored andcommitted
Added code example of how to use message factories (#130)
Added code example of how to use message factories
1 parent b56e406 commit 0a08c07

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

message/message-factory.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,27 @@ This package provides interfaces for PSR-7 factories including:
2929
- ``StreamFactory``
3030
- ``UploadedFileFactory`` - WIP (PRs welcome)
3131
- ``UriFactory``
32+
33+
Implementation for the interfaces above for `Diactoros`_ and `Guzzle PSR-7`_ can be found in ``php-http/message``.
34+
35+
.. code:: php
36+
37+
// Create a PSR-7 request
38+
$factory = new Http\Message\MessageFactory\DiactorosMessageFactory();
39+
$request = $factory->createRequest('GET', 'http://example.com');
40+
41+
// Create a PSR-7 stream
42+
$factory = new Http\Message\StreamFactory\DiactorosStreamFactory();
43+
$stream = $factory->createStream('stream content');
44+
45+
You could also use :doc:`/discovery` to find an installed factory automatically.
46+
47+
.. code:: php
48+
49+
// Create a PSR-7 request
50+
$factory = MessageFactoryDiscovery::find();
51+
$request = $factory->createRequest('GET', 'http://example.com');
52+
53+
54+
.. _Diactoros: https://github.com/zendframework/zend-diactoros
55+
.. _Guzzle PSR-7: https://github.com/guzzle/psr7

0 commit comments

Comments
 (0)