RefreshMiddleware
in package
`HandlerStack` middleware: on a `401` response, triggers the session's single-flight refresh (CONTRACT.md §9, D-06, SC#2) and retries the ORIGINAL request exactly once via the inner `$handler` — never a loop. All concurrent 401-triggering requests on one {@see Session} share the SAME refresh `PromiseInterface` ({@see Session::refreshIfNeeded()}), so N concurrent expired-token requests still result in exactly one `/api/v1/auth/refresh` call.
Pushed BEFORE AuthMiddleware (AxiamClient::$authzStack). HandlerStack runs the
first pushed middleware first on a request, so a request runs Guzzle's http_errors,
redirect, cookie and body middleware, then this middleware, then AuthMiddleware, then the
base handler. The retry — invoked via the $handler captured here, which is everything
INSIDE this middleware, i.e. AuthMiddleware + the base handler — passes through
AuthMiddleware again, so it carries the refreshed bearer token and X-CSRF-Token; the
Cookie header was set by the cookie middleware outside this one and is rebuilt here from the
request's own cookies jar. It never re-enters this middleware's own 401 check a second time (retry-exactly-once by
construction, not by an explicit retry counter).
Table of Contents
Methods
- __construct() : mixed
- __invoke() : callable
- Wraps the next Guzzle handler so a 401 triggers a single-flight token refresh and one replay of the original request.
Methods
__construct()
public
__construct(Session $session) : mixed
Parameters
- $session : Session
-
Session whose access token is refreshed on a 401.
__invoke()
Wraps the next Guzzle handler so a 401 triggers a single-flight token refresh and one replay of the original request.
public
__invoke(callable $handler) : callable
The replay is issued through the NEXT handler rather than the top of the stack, so it cannot re-enter this middleware's 401 check — retry-exactly-once by construction, with no explicit retry counter and no infinite refresh loop.
Parameters
- $handler : callable
-
Next handler in the Guzzle stack.
Return values
callable —Decorated handler.