Skip to content

document how to use discovery #2

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

Closed
dbu opened this issue Aug 23, 2015 · 3 comments · Fixed by #4
Closed

document how to use discovery #2

dbu opened this issue Aug 23, 2015 · 3 comments · Fixed by #4

Comments

@dbu
Copy link
Contributor

dbu commented Aug 23, 2015

the discovery section only explains how to provide discovery for your own project. but i am trying to figure out how to just use discovery in my project. imho the doc should also explain that.

do i simply need to call HttpAdapterDiscovery::find() and thats it?

and for creating messages, i need the MessageFactoryDiscovery::find()->createRequest?

and what is the uri factory for? the MessageFactory accepts a string as well (the doc is incorrect btw, it should state that it can also accept an UriInterface)

i am happy to do a PR to add a usage section, but first want to be sure to understand correctly how things work.

@sagikazarmark
Copy link
Member

The usage of discoveries is covered in the general section.

do i simply need to call HttpAdapterDiscovery::find() and thats it?

Yes, it is that simple.

and for creating messages, i need the MessageFactoryDiscovery::find()->createRequest?

It is not specifically mentioned in the documentation, but IIRC the discovery classes contain docblock about the returned types. MessageFactoryDiscovery returns a MessageFactory which you can use to create messages. While discoveries has caching builtin, I suggest storing the discovered object internally in your class, so that you only have to call the discovery once.

and what is the uri factory for?

IIRC @ddeboer created that one, he specifically needed that and I had nothing to say against it.

the MessageFactory accepts a string as well (the doc is incorrect btw, it should state that it can also accept an UriInterface)

No, it is on purpose. The factory accepts string as well so you can create your request object directly without the need for creating an Uri object first. The other reason it is there is that every PSR-7 implementation differs: one accepts string in it's constructor, another doesn't. This tries to make it consistent: each accepts everything.

I think I answered all your questions. If you feel a PR is still necessary or you think you can improve the docs so that other people won't have to ask these questions again, please feel free to submit a PR.

@dbu
Copy link
Contributor Author

dbu commented Aug 23, 2015

The usage of discoveries is covered in the general
http://php-http.readthedocs.org/en/latest/discovery/#general section.

ah, right. hm but that is rather abstract to read. i will try to do a PR
with a little usage tutorial.

the MessageFactory accepts a string as well (the doc is incorrect
btw, it should state that it can also accept an UriInterface)

No, it is on purpose. The factory accepts string as well so you can
create your request object directly without the need for creating an Uri
object first. The other reason it is there is that every PSR-7
implementation differs: one accepts string in it's constructor, another
doesn't. This tries to make it consistent: each accepts everything.

okay, the doc mistake was in guzzle psr7 Request:
guzzle/psr7#35

@sagikazarmark
Copy link
Member

Looking at the docs, there are code examples about using the specific discoveries as well:

http://php-http.readthedocs.org/en/latest/discovery/#http-adapter-discovery

Thank you for contributing!

sagikazarmark added a commit that referenced this issue Aug 23, 2015
restructure discovery documentation - Fix #1, Fix #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants