Skip to content

Commit

Permalink
docs(readme): update middleware usage in client handler
Browse files Browse the repository at this point in the history
- Removed direct middleware usage for Authenticate and Response.
- Added dynamic middleware loading from defaultMiddlewares method.
- Improved flexibility in handler stack configuration.
  • Loading branch information
guanguans committed Sep 9, 2024
1 parent f3a518c commit 6493bba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,21 @@ $responses = $client->pool($messages);

```php
use Guanguans\Notify\Foundation\Client;
use Guanguans\Notify\Foundation\Middleware\Authenticate;
use Guanguans\Notify\Foundation\Middleware\Response;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Guzzle\HandlerStackFactory;
use Hyperf\Guzzle\PoolHandler;

// Set Handler directly
// $client->setHandler(new PoolHandler);
$client->setHandler(new CoroutineHandler);

// Or set HandlerStackResolver
$client->setHandlerStackResolver(static function (Client $client) {
$handlerStack = (new HandlerStackFactory)->create();
$handlerStack->push(new Authenticate($client->getAuthenticator()), Authenticate::class);
$handlerStack->push(new Response, Response::class);

foreach ($client->defaultMiddlewares() as $name => $middleware) {
$handlerStack->push($middleware, $name);
}

return $handlerStack;
});
Expand Down

0 comments on commit 6493bba

Please sign in to comment.