Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Psr Http Message Bridge Laravel Package

symfony/psr-http-message-bridge

Symfony PSR-7 Bridge integrates PSR-7 HTTP messages with Symfony. Convert between Symfony HttpFoundation requests/responses and PSR-7 implementations, enabling interoperability with PSR-7 middleware, libraries, and frameworks.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • PSR-7 Standardization: The package excels in enabling interoperability between Laravel’s Illuminate\Http and PSR-7 (e.g., Symfony’s HttpFoundation or middleware like zendframework/zend-diactoros). This aligns with modern Laravel architectures adopting PSR-15 middleware (e.g., fruitcake/laravel-psr) or integrating Symfony components (e.g., HTTP client, Messenger).
  • Hybrid Stacks: Ideal for microservices, API gateways, or hybrid Laravel/Symfony applications where shared middleware (auth, logging, rate limiting) or request/response handling is required. Example: A Laravel frontend service consuming a Symfony-based API with PSR-7 responses.
  • Testing/Tooling: Simplifies mocking PSR-7 objects for Symfony components in Laravel tests (e.g., testing Symfony’s HTTP client in a Laravel app).
  • Future-Proofing: Supports incremental migration to Symfony by reusing PSR-7 middleware or components (e.g., Symfony’s UX tools) without rewriting Laravel-specific logic.

Integration Feasibility

  • Low-Coupling Design: The bridge is stateless and focused on conversion logic, minimizing risk of side effects in Laravel’s core. However, integration requires custom adapters to translate between Laravel’s Request/Response and PSR-7 objects (e.g., wrapping the bridge in a service).
  • Dependency Conflicts: Laravel bundles Symfony components (e.g., symfony/http-foundation), which may conflict with the bridge’s version. Mitigation: Use a dedicated service container (e.g., symfony/service-container) or isolate the bridge in a microservice.
  • Cookie/Stream Handling: Fixed in v7.1.4 for partitioned cookies, but edge cases (e.g., large streams, custom headers) may require validation during integration.
  • Middleware Compatibility: Works seamlessly with PSR-15 middleware (e.g., brick/brick, php-http/message), enabling shared middleware layers across Laravel and Symfony.

Technical Risk

Risk Area Severity Mitigation Strategy
Dependency Conflicts High Pin Symfony components to exact versions; use a separate container for the bridge.
Cookie/Stream Issues Medium Test with partitioned cookies, large payloads, and custom headers.
Laravel-Specific Quirks Medium Validate interactions with Laravel’s Request (e.g., files, server params).
Performance Overhead Low Benchmark conversion latency; caching may help for high-throughput APIs.
Long-Term Maintenance Low Symfony’s PSR-7 bridge is stable; align updates with Laravel’s Symfony version.

Key Questions

  1. Why PSR-7? Are we adopting Symfony components (e.g., HTTP client, Messenger) or PSR-15 middleware that require PSR-7? If not, alternatives like fruitcake/laravel-psr may suffice.
  2. Hybrid Architecture? Is this for a microservices/API gateway or incremental migration from Laravel to Symfony? If not, the package adds unnecessary complexity.
  3. Dependency Isolation: How will we handle Symfony version conflicts with Laravel’s bundled components? (e.g., symfony/http-foundation).
  4. Testing Strategy: Will we use this for mocking Symfony components in Laravel tests? If so, validate edge cases (e.g., partitioned cookies).
  5. Middleware Reuse: Are we sharing PSR-15 middleware (e.g., auth, logging) between Laravel and Symfony? If yes, this package enables seamless integration.
  6. Performance Impact: For high-throughput APIs, will the conversion overhead be acceptable? Consider caching or async processing if needed.
  7. Team Expertise: Does the team have experience with Symfony’s HttpFoundation and PSR-7? If not, onboarding may introduce friction.

Integration Approach

Stack Fit

  • Primary Use Cases:
    • Hybrid Laravel/Symfony: Convert between Illuminate\Http\Request/Response and PSR-7 for shared middleware or APIs.
    • Symfony Component Integration: Use Symfony’s HTTP client, Messenger, or UX tools in Laravel via PSR-7 bridges.
    • PSR-15 Middleware: Reuse middleware (e.g., zendframework/zend-diactoros) across Laravel and Symfony services.
    • Testing: Generate PSR-7 mocks for Symfony components in Laravel test suites.
  • Alternatives Considered:
    • fruitcake/laravel-psr: Lighter-weight PSR-15 support without Symfony integration.
    • Custom adapters: Higher maintenance but avoid Symfony dependencies.
  • Stack Compatibility:
    • Laravel 8+: Compatible with Laravel’s Symfony 5.4+ components.
    • PHP 8.1+: Required for Symfony 6+ (Laravel 9+). PHP 8.4+ needed for Symfony 8.
    • PSR-15 Middleware: Works with any PSR-15-compliant middleware (e.g., brick/brick).

Migration Path

  1. Assessment Phase:
    • Audit dependencies for Symfony version conflicts (e.g., symfony/http-foundation).
    • Identify use cases (middleware reuse, API integration, testing) to justify adoption.
  2. Proof of Concept (PoC):
    • Implement a minimal bridge service to convert Request/Response ↔ PSR-7.
    • Test with shared middleware (e.g., auth, logging) and Symfony components (e.g., HTTP client).
    • Validate edge cases (cookies, streams, custom headers).
  3. Incremental Rollout:
    • Phase 1: Integrate in a non-critical microservice (e.g., API gateway).
    • Phase 2: Extend to shared middleware layers or Symfony component usage.
    • Phase 3: Adopt in testing infrastructure for PSR-7 mocks.
  4. Dependency Management:
    • Use Composer’s replace or conflict directives to avoid Symfony version clashes.
    • Consider a separate container (e.g., symfony/service-container) for the bridge.

Compatibility

Component Compatibility Notes
Laravel 8–10 Works with Symfony 5.4–8.x; validate version alignment with Laravel’s bundled components.
PHP 8.1–8.4 Symfony 6+ requires PHP 8.1+; Symfony 8 requires PHP 8.4+.
PSR-15 Middleware Fully compatible with any PSR-15 middleware (e.g., zendframework/zend-diactoros).
Symfony Components Enables integration with Symfony’s HTTP client, Messenger, etc.
Laravel Middleware Requires custom adapters to convert between Illuminate\Http and PSR-7.
Testing Frameworks Useful for mocking PSR-7 objects in Laravel tests (e.g., PestPHP, PHPUnit).

Sequencing

  1. Dependency Setup:
    • Add the bridge via Composer:
      composer require symfony/psr-http-message-bridge
      
    • Resolve Symfony version conflicts (e.g., via composer.json constraints).
  2. Bridge Service Creation:
    • Create a service to wrap the bridge (e.g., Psr7BridgeService):
      use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
      use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
      
      class Psr7BridgeService {
          public function toPsr7(Request $request): ServerRequestInterface {
              return (new DiactorosFactory())->createRequest($request);
          }
      
          public function toLaravel(ServerRequestInterface $request): Request {
              return (new HttpFoundationFactory())->createRequest($request);
          }
      }
      
  3. Middleware Integration:
    • Register PSR-15 middleware in Laravel’s kernel (e.g., via fruitcake/laravel-psr):
      $app->middleware(\App\Middleware\Psr15AuthMiddleware::class);
      
  4. API/Symfony Component Integration:
    • Use the bridge to convert responses from Symfony APIs to Laravel-compatible formats.
  5. Testing Integration:
    • Replace Symfony component tests with PSR-7 mocks converted via the bridge.

Operational Impact

Maintenance

  • Dependency Updates:
    • Align updates with Laravel’s Symfony component versions to avoid conflicts.
    • Monitor Symfony’s PSR-7 bridge for backward compatibility breaks (low risk; Symfony follows semantic versioning).
  • Custom Code:

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport