tourze/psr15-symfony-request-request-handler

PSR-15 Symfony Request Handler

0.0.3 2025-04-25 02:32 UTC

This package is auto-updated.

Last update: 2025-04-28 03:05:11 UTC


README

PHP Version Build Status License

A PSR-15 compatible HTTP request handler for integrating Symfony's HttpKernel and HttpFoundation with the PSR-7/PSR-15 ecosystem. This package enables seamless conversion between PSR-7 requests and Symfony requests, and provides robust handling for authentication headers, HTTPS forwarding, and error logging.

Features

  • PSR-15 RequestHandlerInterface implementation
  • Converts PSR-7 ServerRequest to Symfony Request and vice versa
  • Handles HTTPS proxy headers (e.g., Force-Https)
  • Supports real IP forwarding (X-Real-IP)
  • Handles Authorization headers (Basic, Digest, Bearer)
  • Automatic error logging with exception details
  • Designed for high compatibility with Symfony and PSR standards

Installation

Requirements:

  • PHP ^8.1
  • Symfony 6.4+
  • PSR-7, PSR-15 compatible packages

Install via Composer:

composer require tourze/psr15-symfony-request-request-handler

Quick Start

use Tourze\PSR15SymfonyRequestHandler\SymfonyRequestHandler;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

$handler = new SymfonyRequestHandler(
    $kernel, // instance of HttpKernelInterface
    new HttpFoundationFactory(),
    new PsrHttpFactory(...),
    $logger // optional PSR logger
);

$response = $handler->handle($psrRequest);

Documentation

  • Handles all HTTP methods supported by Symfony
  • Converts cookies and headers for maximum compatibility
  • Supports custom request/response injection for advanced scenarios
  • Error handling: logs uncaught exceptions and returns error details in response

Advanced Usage:

  • You can set/get the internal Symfony Request/Response via setRequest(), getRequest(), setResponse(), getResponse()
  • Handles edge cases for Authorization and HTTPS headers

Contributing

  • Please submit issues and pull requests via GitHub
  • Follow PSR coding standards
  • Ensure all tests pass (phpunit)
  • Run static analysis (phpstan)

License

MIT License. See LICENSE for details.

Changelog

See Git history for detailed changes. Major features and bugfixes are documented in release notes.