From b9c69383ff0accb37643daaff2f8c63d94475baf Mon Sep 17 00:00:00 2001 From: guanguans Date: Wed, 11 Sep 2024 20:57:11 +0800 Subject: [PATCH] docs(README): Improve HandlerStackResolver example - Added import for GuzzleHttp\HandlerStack. - Refactored HandlerStackResolver implementation to use array_reduce for cleaner code. - Enhanced readability and maintainability of the example. --- README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aefcd13..f9674f5 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ $responses = $client->pool($messages); ```php use Guanguans\Notify\Foundation\Client; +use GuzzleHttp\HandlerStack; use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Guzzle\HandlerStackFactory; use Hyperf\Guzzle\PoolHandler; @@ -150,15 +151,11 @@ use Hyperf\Guzzle\PoolHandler; $client->setHandler((fn () => $this->getHandler($this->option))->call(new HandlerStackFactory)); // Or set HandlerStackResolver -$client->setHandlerStackResolver(static function (Client $client) { - $handlerStack = (new HandlerStackFactory)->create(); - - foreach ($client->defaultMiddlewares() as $name => $middleware) { - $handlerStack->push($middleware, $name); - } - - return $handlerStack; -}); +$client->setHandlerStackResolver(static fn (Client $client): HandlerStack => array_reduce( + $client->defaultMiddlewares(), + static fn (HandlerStack $handlerStack, callable $middleware) => tap($handlerStack)->push($middleware), + (new HandlerStackFactory)->create() +)); ``` ### Completion