Skip to content

Commit

Permalink
docs(README): Improve HandlerStackResolver example
Browse files Browse the repository at this point in the history
- Added import for GuzzleHttp\HandlerStack.
- Refactored HandlerStackResolver implementation to use array_reduce for cleaner code.
- Enhanced readability and maintainability of the example.
  • Loading branch information
guanguans committed Sep 11, 2024
1 parent 6bc0b36 commit b9c6938
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit b9c6938

Please sign in to comment.