$ show nelmio/NelmioCorsBundle
This is a Symfony bundle that adds Cross-Origin Resource Sharing (CORS) headers to HTTP responses and handles CORS preflight OPTIONS requests. It intercepts kernel request and response events, applies configurable per-URL rules (origin matching, allowed methods/headers, credentials, private network access, forced origin values, etc.), and automatically adds a `Vary: Origin` header to cacheable responses. The bundle is well-structured with a clean provider/resolver pattern for configuration, supports Symfony 5.4 through 8.0 and PHP 7.2+, and includes full CI and static analysis. It is a mature, actively maintained library that solves a specific HTTP security concern in a robust and extensible manner.
The LLM identified 2 files worth highlighting for reuse:
Implements the ProviderInterface to resolve CORS options for a given request by matching the request URI against configured path patterns. Merges per-path options with global defaults and supports host-based filtering. The pattern of merging defaults with overrides is reusable in any configuration system requiring layered resolution.
Aggregates multiple CORS option providers into a single resolver. Iterates over an ordered list of providers and merges their returned options using array_merge. This is a clean implementation of the Chain of Responsibility pattern for configuration resolution, reusable whenever multiple independent sources need to contribute to a combined configuration.