beberlei/pecl_http — pull request #1 by beberlei (2012-03-25 12:18:26+00:00)
Title: API Refactoring

Goal:

* Avoid userland wrappers of pecl/http through carefully object-oriented crafted API.
* Avoid users having to write boilerplate to "mock" the http client functionality.

Big picture

* Seperate building request/response from actually sending it
* Achieve more consistent API by moving towards single responsibility of objects
* Introduce interfaces and build interaction between objects such that dependency injection is possible (not necessary).

Small steps

* Refactor http\Request\Factory to http\Request\Client (interface) and http\Request\CurlClient

Have a method http_client_create() that could create a default CurlClient, for very easy usage.

* Remove http\Request#send()

Not the request sends itself, a HTTP Client sends a request
* Remove http\Request#getResponse*()

Since a request can be fired more then once, it has no 1:1 relationship to a response.
Additionally with Client#send($request) returning a response it doesn't make sense to offer
the same functionality in two different ways. Just having one way is more consistent and easy
to learn.

* Remove http\Request#getHistory()

Not a request has a history, a client has the history
* Make http\Request a "value" object, no reference to client.

You can create request objects in your code with "new http\Request"
as they only contain values and no "client/sending" logic.