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:
parent
591abb4620
commit
eac6f01d58
1 changed files with 19 additions and 31 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue