Skip to content

Commit

Permalink
Added a section about contribution and fixed typos (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Feb 2, 2019
1 parent 66c7776 commit ab28eef
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Expand Up @@ -62,7 +62,7 @@ All exceptions will be handled in the callback.
- Added `ParameterBag` to store options.
- Added `BatchClientInterface::sendAsyncRequest(RequestInterface $request, array $options = [])`.
- Added `BuzzClientInterface::sendRequest(RequestInterface $request, array $options = []): ResponseInterface`.
- Ported all Listeners to Middlewares.
- Ported all Listeners to Middleware.
- Added options to configure the client as constructor argument and when you send a request.

### Removed (BC breaks)
Expand Down Expand Up @@ -123,7 +123,7 @@ All exceptions will be handled in the callback.
* Added Request and Response converters
* Added `Curl::sendRequest()`, `MultiCurl::sendRequest()` and `FileGetContents::sendRequest()` that
supports sending PSR-7 requests.
* Added `Browser::sendRequest()` that supports middlewares.
* Added `Browser::sendRequest()` that supports middleware.
* Added `MiddlewareInterface` and `Browser::addMiddleware()`.
* Added `HeaderConverter` to convert between PSR-7 styled headers and Buzz styled headers.

Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -132,6 +132,14 @@ compatibility.
Being greatly inspired by [Symfony's bc promise](https://symfony.com/doc/current/contributing/code/bc.html), we have adopted
their method of deprecating classes, interfaces and functions.

## Contribute

Buzz is great because it is small, simple and yet flexible. We are always happy to receive bug reports and bug fixes. We
are also looking forward to review a pull request with a new middleware, especially if the middleware covers a common
use case.

We will probably not accept any configuration option or feature to any of the clients or the Browser.

## Running the tests

There are 2 kinds of tests for this library; unit tests and integration tests. They can be run separably by:
Expand Down
2 changes: 1 addition & 1 deletion doc/index.md → doc/Readme.md
Expand Up @@ -7,7 +7,7 @@ reading.
* [Browser](#browser)
* [Submit forms](#submit-a-form)
* [Client](/doc/client.md)
* [Middlewares](/doc/middlewares.md)
* [Middleware](/doc/middleware.md)
* [Symfony Bundle](/doc/symfony.md)


Expand Down
10 changes: 5 additions & 5 deletions doc/client.md
@@ -1,4 +1,4 @@
[<-- Index](/doc/index.md)
[<-- Index](/doc/Readme.md)

# Clients

Expand Down Expand Up @@ -94,10 +94,10 @@ A proxy server to use when sending requests.
#### push_function_callback

Type: callable, null<br>
Default: `null`
Default: `null`<br>
*Only for MultiCurl*

A callable for `CURLMOPT_PUSHFUNCTION`. See [PHP docs](http://php.net/manual/en/function.curl-multi-setopt.php)
A callable for `CURLMOPT_PUSHFUNCTION`. See [PHP docs](http://php.net/manual/en/function.curl-multi-setopt.php).

Since MultiCurl supports adding multiple requests, all Push Functions callbacks are
chained together. If one of them returns `CURL_PUSH_DENY`, then the request will be denied.
Expand All @@ -124,7 +124,7 @@ The time to wait before interrupt the request.
#### use_pushed_response

Type: boolean<br>
Default: `true`
Default: `true`<br>
*Only for MultiCurl*

If true, we can used responses pushed to us by HTTP/2.0 server push.
Expand All @@ -138,4 +138,4 @@ If SSL protocols should verified.

---

Continue reading about [Middlewares](/doc/middlewares.md).
Continue reading about [Middleware](/doc/middleware.md).
6 changes: 3 additions & 3 deletions doc/middlewares.md → doc/middleware.md
@@ -1,10 +1,10 @@
[<-- Index](/doc/index.md)
[<-- Index](/doc/Readme.md)

# Buzz middlewares
# Buzz middleware

If you want to modify the request or response somehow, a middleware is the way to
go. Every time you send a request with the `Browser` it will run through all the
middlewares. The order of the middlewares is important. The first middleware added
middleware. The order of the middleware is important. The first middleware added
to the `Browser` will be the first one that is executed when handling the request and
the last one to be executed when handling the response.

Expand Down
4 changes: 2 additions & 2 deletions doc/symfony.md
@@ -1,4 +1,4 @@
[<-- Index](/doc/index.md)
[<-- Index](/doc/Readme.md)

# Symfony integration

Expand Down Expand Up @@ -44,4 +44,4 @@ plugins method clients and whatever you want according to the

---

Go back to [index](/doc/index.md).
Go back to [index](/doc/Readme.md).
16 changes: 8 additions & 8 deletions lib/Browser.php
Expand Up @@ -25,7 +25,7 @@ class Browser implements BuzzClientInterface
/**
* @var MiddlewareInterface[]
*/
private $middlewares = [];
private $middleware = [];

/** @var RequestInterface */
private $lastRequest;
Expand Down Expand Up @@ -143,7 +143,7 @@ public function submitForm(string $url, array $fields, string $method = 'POST',
*/
public function sendRequest(RequestInterface $request, array $options = []): ResponseInterface
{
$chain = $this->createMiddlewareChain($this->middlewares, function (RequestInterface $request, callable $responseChain) use ($options) {
$chain = $this->createMiddlewareChain($this->middleware, function (RequestInterface $request, callable $responseChain) use ($options) {
$response = $this->client->sendRequest($request, $options);
$responseChain($request, $response);
}, function (RequestInterface $request, ResponseInterface $response) {
Expand All @@ -158,15 +158,15 @@ public function sendRequest(RequestInterface $request, array $options = []): Res
}

/**
* @param MiddlewareInterface[] $middlewares
* @param MiddlewareInterface[] $middleware
*/
private function createMiddlewareChain(array $middlewares, callable $requestChainLast, callable $responseChainLast): callable
private function createMiddlewareChain(array $middleware, callable $requestChainLast, callable $responseChainLast): callable
{
$responseChainNext = $responseChainLast;

// Build response chain
/** @var MiddlewareInterface $middleware */
foreach ($middlewares as $middleware) {
foreach ($middleware as $middleware) {
$lastCallable = function (RequestInterface $request, ResponseInterface $response) use ($middleware, $responseChainNext) {
return $middleware->handleResponse($request, $response, $responseChainNext);
};
Expand All @@ -179,12 +179,12 @@ private function createMiddlewareChain(array $middlewares, callable $requestChai
$requestChainLast($request, $responseChainNext);
};

$middlewares = array_reverse($middlewares);
$middleware = array_reverse($middleware);

// Build request chain
$requestChainNext = $requestChainLast;
/** @var MiddlewareInterface $middleware */
foreach ($middlewares as $middleware) {
foreach ($middleware as $middleware) {
$lastCallable = function (RequestInterface $request) use ($middleware, $requestChainNext) {
return $middleware->handleRequest($request, $requestChainNext);
};
Expand Down Expand Up @@ -215,7 +215,7 @@ public function getClient(): BuzzClientInterface
*/
public function addMiddleware(MiddlewareInterface $middleware): void
{
$this->middlewares[] = $middleware;
$this->middleware[] = $middleware;
}

private function prepareMultipart(string $name, string $content, string $boundary, array $data = []): string
Expand Down

0 comments on commit ab28eef

Please sign in to comment.