From 92bf785d5307f4c82799b75a67c1f12d1b670080 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 2 Feb 2019 16:04:00 +0100 Subject: [PATCH] Added a section about contribution and fixed typos --- CHANGELOG.md | 4 ++-- README.md | 8 ++++++++ doc/{index.md => Readme.md} | 2 +- doc/client.md | 10 +++++----- doc/{middlewares.md => middleware.md} | 6 +++--- doc/symfony.md | 4 ++-- lib/Browser.php | 16 ++++++++-------- 7 files changed, 29 insertions(+), 21 deletions(-) rename doc/{index.md => Readme.md} (98%) rename doc/{middlewares.md => middleware.md} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf397764..8dbd4feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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. diff --git a/README.md b/README.md index 275ba5d2..8ab7720f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/doc/index.md b/doc/Readme.md similarity index 98% rename from doc/index.md rename to doc/Readme.md index 5564631f..30a63b5f 100644 --- a/doc/index.md +++ b/doc/Readme.md @@ -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) diff --git a/doc/client.md b/doc/client.md index ca765001..062c9911 100644 --- a/doc/client.md +++ b/doc/client.md @@ -1,4 +1,4 @@ -[<-- Index](/doc/index.md) +[<-- Index](/doc/Readme.md) # Clients @@ -94,10 +94,10 @@ A proxy server to use when sending requests. #### push_function_callback Type: callable, null
-Default: `null` +Default: `null`
*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. @@ -124,7 +124,7 @@ The time to wait before interrupt the request. #### use_pushed_response Type: boolean
-Default: `true` +Default: `true`
*Only for MultiCurl* If true, we can used responses pushed to us by HTTP/2.0 server push. @@ -138,4 +138,4 @@ If SSL protocols should verified. --- -Continue reading about [Middlewares](/doc/middlewares.md). +Continue reading about [Middleware](/doc/middleware.md). diff --git a/doc/middlewares.md b/doc/middleware.md similarity index 95% rename from doc/middlewares.md rename to doc/middleware.md index 08b8d2f7..ba396920 100644 --- a/doc/middlewares.md +++ b/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. diff --git a/doc/symfony.md b/doc/symfony.md index bcd84bb6..e4babacb 100644 --- a/doc/symfony.md +++ b/doc/symfony.md @@ -1,4 +1,4 @@ -[<-- Index](/doc/index.md) +[<-- Index](/doc/Readme.md) # Symfony integration @@ -44,4 +44,4 @@ plugins method clients and whatever you want according to the --- -Go back to [index](/doc/index.md). \ No newline at end of file +Go back to [index](/doc/Readme.md). \ No newline at end of file diff --git a/lib/Browser.php b/lib/Browser.php index c7739ae7..325b5a65 100644 --- a/lib/Browser.php +++ b/lib/Browser.php @@ -25,7 +25,7 @@ class Browser implements BuzzClientInterface /** * @var MiddlewareInterface[] */ - private $middlewares = []; + private $middleware = []; /** @var RequestInterface */ private $lastRequest; @@ -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) { @@ -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); }; @@ -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); }; @@ -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