Skip to content

Added code example of how to use message factories #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions message/message-factory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ This package provides interfaces for PSR-7 factories including:
- ``StreamFactory``
- ``UploadedFileFactory`` - WIP (PRs welcome)
- ``UriFactory``

Implementation for the interfaces above for `Diactoros`_ and `Guzzle PSR-7`_ can be found in ``php-http/message``.

.. code:: php

// Create a PSR-7 request
$factory = new Http\Message\MessageFactory\DiactorosMessageFactory();
$request = $factory->createRequest('GET', 'http://example.com');

// Create a PSR-7 stream
$factory = new Http\Message\StreamFactory\DiactorosStreamFactory();
$stream = $factory->createStream('stream content');

You could also use :doc:`/discovery` to find an installed factory automatically.

.. code:: php

// Create a PSR-7 request
$factory = MessageFactoryDiscovery::find();
$request = $factory->createRequest('GET', 'http://example.com');


.. _Diactoros: http://docs.guzzlephp.org/en/5.3/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the correct link. searching for "Diactoros" on the linked page finds nothing. shouldn't this link to something zend framework?

Copy link
Member Author

@Nyholm Nyholm Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a copy-paste error.

#129

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. can you rebase and fix this?

.. _Guzzle PSR-7: https://github.com/guzzle/psr7