Improve middleware pipeline consistency (#262)

- Make MiddlewareRequestHandler final and use index counter instead of
  array_shift to avoid mutating internal state
- Make OAuthProxyMiddleware factory discovery consistently lazy via
  getter methods, matching httpClient and requestFactory pattern

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christopher Hertel 2026-03-11 10:25:23 +01:00 • committed by GitHub
commit eac6f01d58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,24 +24,25 @@ use Psr\Http\Server\RequestHandlerInterface;
*
* @internal
*/
class MiddlewareRequestHandler implements RequestHandlerInterface
final class MiddlewareRequestHandler implements RequestHandlerInterface
{
private int $index = 0;
/**
* @param list<MiddlewareInterface> $middleware
*/
public function __construct(
private array $middleware,
private \Closure $application,
private readonly array $middleware,
private readonly \Closure $application,
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$middleware = array_shift($this->middleware);
if (null === $middleware) {
if (!isset($this->middleware[$this->index])) {
return ($this->application)($request);
}
return $middleware->process($request, $this);
return $this->middleware[$this->index++]->process($request, $this);
}
}