PSR-15 Queue

Changelog

v2.0.0

Breaking Changes:

  • MiddlewareQueue is no longer a singleton, so every QueueRequestHandler now gets its own queue of middlewares. Previously all handlers shared one queue and middlewares passed to any but the first handler were silently ignored. Use new MiddlewareQueue() instead of MiddlewareQueue::getInstance() .
  • QueueRequestHandler::handle() now works on a copy of the middleware queue for each request, so one handler can process any number of requests (e.g. in long-running servers like RoadRunner, Swoole or FrankenPHP). Previously every call after the first returned the stale response of the first run without invoking any middleware. While a request is being handled, QueueRequestHandler::queue returns that request's copy, so changes made by middlewares only apply to the current request.
  • QueueRequestHandler no longer catches exceptions thrown by a middleware. As intended by PSR-15, they are now passed through all previous middlewares, so these can handle them as needed, and finally to the caller of handle() . Add the new ErrorMiddleware as the first middleware to convert them into responses. Error responses no longer reveal any details to the client and the Warning header was removed (see below).
  • AbstractMiddleware now works with any request handler implementing PsrHttpServerRequestHandlerInterface instead of throwing a DomainException for anything but a QueueRequestHandler . Therefore the type of the protected property AbstractMiddleware::requestHandler changed to RequestHandlerInterface . Middlewares accessing properties of QueueRequestHandler (e.g. $this->requestHandler->request ) still work with it, but static analyzers will report them unless you check the type with instanceof QueueRequestHandler first.
  • guzzlehttp/psr7 is no longer a required dependency. The package now works with any PSR-7 and PSR-17 implementation. Guzzle is still used by default if it's installed, so add it to your own dependencies if you rely on it (composer require guzzlehttp/psr7 ). Otherwise, pass the server request and a response factory to the constructors of QueueRequestHandler and ErrorMiddleware .

Minor Changes:

  • Added ErrorMiddleware to convert any exception or error (i.e. every Throwable ) into an HTTP error response. By default, the response only states the HTTP status and the details are written to PHP's error log. The exception code is used as status if it's a valid HTTP error status (400 to 599 ), otherwise it's 500 . A custom error handler can be passed to the constructor.
  • Added optional server request and PSR-17 response factory as second and third argument to the constructor of QueueRequestHandler , and an optional response factory as second argument to the constructor of ErrorMiddleware .

Bugfixes:

  • QueueRequestHandler::respond() now sends every header value as a separate header line. Previously multiple values were combined into one comma-separated line, which broke responses setting more than one cookie. Headers already set by PHP (e.g. Cache-Control from session_start() ) are now replaced instead of being sent twice, except for cookies.
  • QueueRequestHandler::respond() now sends the status line after all other headers. Previously PHP silently changed the status code to 302 when a Location header was present (unless the status was 201 or 3xx ), and to 401 when a WWW-Authenticate header was present, e.g. turning a 202 Accepted into a redirect.

Maintenance:

  • Added a test suite for PHPUnit (run with composer phpunit:test ), which is run for every supported PHP version (8.1 to 8.5) on GitHub
  • Excluded the documentation, tests and configuration files of development tools from the Composer package, so it only contains the source code, composer.json , LICENSE and README.md
  • The documentation is no longer part of the repository, but built and deployed to GitHub Pages automatically for every release. To read it offline, build it locally with composer phpdoc:build
  • All code checks on GitHub now run the tool versions installed by Composer on PHP 8.5, just like when running them locally, instead of using different third-party actions and Docker images
  • Updated Psalm to version 7 (still version 6 on PHP 8.1, which isn't supported by Psalm 7)

v1.3.1

Maintenance:

v1.3.0

Minor Changes:

Maintenance:

  • Raised PHPStan rule level to 10

v1.2.1

Maintenance:

  • Updated dependencies
  • Added annotations, removed redundant type hints, and made classes final where appropriate

v1.2.0

Minor Changes:

  • Added a Warning header to identify response messages from converted exceptions
  • Removed the option to provide an exit status to QueueRequestHandler::respond()
  • Added Composer command for development tools (PHP Mess Detector, Psalm Taint Analysis)

Maintencance:

  • Updated dependencies

v1.1.0

New Features:

Minor Changes:

  • Added Composer commands for development tools (PHP_CodeSniffer, PHP-CS-Fixer, PHPStan, Psalm and phpDocumentor)

Maintencance:

  • Updated dependencies

v1.0.1

Maintenance:

  • Updated dependencies

v1.0.0

Initial Release

Search results