kernel.response event) to inject headers dynamically. Laravel’s middleware pipeline (Kernel::handle()) could replicate this behavior with minimal overhead.Route::get() vs. Symfony’s PathInfo).config/headers.php) or environment variables. A hybrid approach (e.g., YAML parsed into PHP config) could bridge this gap.Events facade or middleware hooks (e.g., terminating middleware) can replace Symfony’s event listener with minimal refactoring.HttpFoundation and EventDispatcher. Laravel’s Illuminate\Http\Response is compatible but may require adapter classes (e.g., SymfonyBridge).Route::get() syntax differs from Symfony’s PathInfo, risking misconfiguration.symfony/http-foundation)? If not, what’s the cost to add them?config/headers.php?symfony/http-kernel, integration is straightforward. Otherwise, a lightweight adapter (e.g., SymfonyResponseWrapper) can bridge Illuminate\Http\Response and Symfony\Component\HttpFoundation\Response.config/headers.php using a service provider’s boot() method, e.g.:
$headers = config('headers.headers');
foreach ($headers as $header) {
// Register middleware or event listener dynamically
}
Phase 1: Proof of Concept
public function handle($request, Closure $next) {
$response = $next($request);
$response->headers->add(['Content-Security-Policy' => 'default-src \'self\'']);
return $response;
}
Phase 2: Conditional Logic
Route::current() or request()->is()):
if ($request->is('api/*')) {
$response->headers->add(['Access-Control-Allow-Origin' => '*']);
}
Phase 3: Full Bundle Replacement
public function boot() {
foreach (config('headers.headers') as $header) {
$this->app->make(\App\Middleware\HeaderMiddleware::class)
->addHeader($header['name'], $header['value'], $header['condition'] ?? null);
}
}
Response object.request()->is(), Route::current()). Content-type checks can use str_starts_with($response->headers->get('Content-Type'), 'image/').config/headers.php is easier to maintain than YAML for teams familiar with PHP. However, YAML may be preferred for non-developers.app/Http/Kernel.php) than event listeners. The bundle’s YAML config adds an abstraction layer that may require additional tooling (e.g., config validation).config:clear and config:cache commands can manage header configurations.request and response objects directly, while the bundle’s YAML is static.request()->is() is stricter than Symfony’s PathInfo matching.Cache-Control) may cause issues. Middleware can deduplicate headers before injection.EventDispatcher) add complexity..env) could reduce friction.php artisan config:validate) should be added for header configurations.How can I help you explore Laravel packages today?