symfony/http-foundation
Symfony HttpFoundation provides an object-oriented abstraction for HTTP requests and responses: manage headers, cookies, sessions, files, streams, and status codes consistently across PHP apps, with tools for building robust web and API interactions.
Laravel Compatibility: The package is PSR-7 compliant and Symfony’s HttpFoundation, which Laravel already uses internally (e.g., Illuminate\Http\Request extends Symfony\Component\HttpFoundation\Request). This ensures zero architectural friction—Laravel’s core HTTP layer is built atop it.
Request → Laravel’s Illuminate\Http\RequestResponse → Laravel’s Illuminate\Http\ResponseUploadedFile → Laravel’s Illuminate\Http\UploadedFileModularity: The package is componentized (e.g., session handling, file uploads, cookies) but not monolithic. A TPM can opt-in to specific features (e.g., only use Request/Response without sessions) to avoid bloat.
BinaryFileResponse for partial content (HTTP 206) without adopting session storage.Future-Proofing: Laravel’s long-term roadmap (e.g., Laravel 11+) aligns with Symfony 8/9. The package’s backward compatibility (e.g., v6.4.x for PHP 7.4+) ensures gradual upgrades without breaking changes.
Laravel’s Built-in Usage:
symfony/http-foundation). Direct dependency risks version conflicts or redundancy.Request, Response) instead of adding this as a standalone package. If custom logic is needed (e.g., advanced session handling), extend Laravel’s classes or use Symfony’s standalone components via Composer.// Instead of:
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
// Use Laravel’s native (which internally uses HttpFoundation):
use Illuminate\Http\Request;
$request = Request::capture();
Custom Middleware/Providers:
Request::setTrustedProxies() in AppServiceProvider.PdoSessionHandler for database-backed sessions.// app/Providers/AppServiceProvider.php
public function boot()
{
Request::setTrustedProxies(['192.168.1.0/24'], Request::HEADER_X_FORWARDED_ALL);
}
API/CLI Hybrid Apps:
Request::create() for testing or mocking).Version Alignment:
symfony/http-foundation directly may cause version conflicts or unexpected behavior.symfony/http-foundation:^8.0 for Laravel 11+).PHP Version Support:
symfony/http-foundation:^7.4 for PHP 8.0+ or ^6.4 for PHP 7.4+.Session Storage Complexity:
PdoSessionHandler) require database schema changes or Redis/Memcached setup.file) and gradually migrate to custom handlers.Performance Overhead:
ab or Laravel’s debugbar before adoption.Scope Clarity:
Dependency Strategy:
Feature Prioritization:
UploadedFile vs. Illuminate\Http\UploadedFile)?Testing & QA:
updateTimestamp() fix) that require testing?Long-Term Maintenance:
Laravel Ecosystem:
Illuminate\Http is a thin wrapper around HttpFoundation. No need to "integrate"—just leverage existing classes.BinaryFileResponse) via Composer for features not in Laravel.Laravel 11 (PHP 8.2+) → Symfony 8.0 → HttpFoundation v8.0
Non-Laravel PHP:
Request::create() for testing).Complementary Packages:
symfony/http-kernel for middleware pipelines.league/flysystem for cloud storage + UploadedFile.symfony/cache for Response caching.| Current State | Migration Path | Tools/Steps |
|---|---|---|
Procedural HTTP ($_GET, $_POST) |
Replace with Request::createFromGlobals() or Laravel’s Request::capture(). |
- Use Request::all() for superglobal access. - Replace $_FILES with UploadedFile. |
| Custom Request Parsing | Use Request methods (e.g., getQueryParams(), getContent()). |
- Refactor parsing logic into middleware. - Use Request::get() for typed access. |
| Laravel’s HTTP Layer | Extend with Symfony’s standalone components (e.g., BinaryFileResponse). |
- Composer: composer require symfony/http-foundation:^8.0. - Avoid conflicts by using Laravel’s classes. |
| No HTTP Abstraction | Adopt Request/Response for new features (e.g., APIs, file uploads). |
- Start with a single feature (e.g., sessions) and expand. - Use Request::create() for testing. |
Laravel Versions:
symfony/http-foundation:^7.4 or ^8.0 (aligned with Laravel’s Symfony version).^6.4 (PHP 8.0+).^5.4 (PHP 7.4+).PHP Versions:
^8.0 (latest features, e.g., PHP 8.6 fixes).How can I help you explore Laravel packages today?