{"id":18794574,"url":"https://github.com/effectra/cors","last_synced_at":"2025-12-29T19:30:14.031Z","repository":{"id":215838928,"uuid":"739417815","full_name":"effectra/cors","owner":"effectra","description":"PHP library for enabling CORS (Cross-Origin Resource Sharing) in HTTP requests/responses. It follows PSR guidelines, and can be easily integrated into PHP projects.","archived":false,"fork":false,"pushed_at":"2024-01-06T21:46:38.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-29T16:34:09.874Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/effectra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-05T14:16:06.000Z","updated_at":"2024-05-01T01:33:23.000Z","dependencies_parsed_at":"2024-01-06T22:30:48.564Z","dependency_job_id":null,"html_url":"https://github.com/effectra/cors","commit_stats":null,"previous_names":["effectra/cors"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effectra%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/effectra","download_url":"https://codeload.github.com/effectra/cors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239718733,"owners_count":19685806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T21:29:49.667Z","updated_at":"2025-12-29T19:30:11.968Z","avatar_url":"https://github.com/effectra.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Effectra/cors\n\nEffectra/cors is a PHP package that provides middleware and service classes for handling Cross-Origin Resource Sharing (CORS) in web applications. CORS is a security feature implemented by web browsers to control access to resources on a different origin.\n\n## Installation\n\nYou can install the Effectra/cors package via Composer:\n\n```bash\ncomposer require effectra/cors\n```\n\n## Usage\n\n### CorsMiddleware\n\nThe `CorsMiddleware` class is a PSR-15 middleware that can be used in a middleware stack to handle CORS requests. It checks incoming requests for CORS-related headers and adds appropriate headers to the response.\n\n#### Example:\n\n```php\nuse Effectra\\Cors\\CorsMiddleware;\nuse Effectra\\Cors\\CorsService;\nuse Psr\\Http\\Server\\MiddlewareInterface;\n\n// Create a CorsService instance with desired configuration\n$corsService = new CorsService([\n    'allowedOrigins' =\u003e ['https://example.com'],\n    'allowedMethods' =\u003e ['GET', 'POST'],\n    'allowedHeaders' =\u003e ['Content-Type'],\n]);\n\n// Create the CorsMiddleware instance\n$corsMiddleware = new CorsMiddleware($corsService, ['/api']);\n\n// Add the middleware to your middleware stack\n$middlewareStack = [\n    // Other middleware...\n    $corsMiddleware,\n    // Other middleware...\n];\n```\n\n### CorsService\n\nThe `CorsService` class provides the core functionality for handling CORS requests. It allows you to configure various CORS-related settings.\n\n#### Example:\n\n```php\nuse Effectra\\Cors\\CorsService;\n\n// Create a CorsService instance with desired configuration\n$corsService = new CorsService([\n    'allowedOrigins' =\u003e ['https://example.com'],\n    'allowedMethods' =\u003e ['GET', 'POST'],\n    'allowedHeaders' =\u003e ['Content-Type'],\n]);\n\n// Check if a request is a CORS request\n$isCorsRequest = $corsService-\u003eisCorsRequest($request);\n\n// Check if a request is a preflight request\n$isPreflightRequest = $corsService-\u003eisPreflightRequest($request);\n\n// Handle a preflight request and add necessary headers to the response\n$preflightResponse = $corsService-\u003ehandlePreflightRequest($request);\n\n// Check if a specific origin is allowed\n$isOriginAllowed = $corsService-\u003eisOriginAllowed($request);\n\n// Add CORS headers to the actual response\n$actualResponse = $corsService-\u003eaddActualRequestHeaders($response, $request);\n```\n\n## Configuration\n\nThe `CorsService` class allows you to configure various CORS-related settings using an options array.\n\n### Available Options:\n\n- `allowedOrigins`: An array of allowed origins.\n- `allowedOriginsPatterns`: An array of allowed origin patterns (wildcards).\n- `allowedMethods`: An array of allowed HTTP methods.\n- `allowedHeaders`: An array of allowed headers.\n- `supportsCredentials`: Whether credentials (cookies, HTTP authentication) should be supported.\n- `maxAge`: Maximum time (in seconds) that the results of a preflight request can be cached.\n- `exposedHeaders`: An array of headers exposed to the response.\n\n## Contributing\n\nIf you'd like to contribute to this project, please follow our [contribution guidelines](CONTRIBUTING.md).\n\n## License\n\nThe Effectra/cors package is open-sourced software licensed under the [MIT license](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffectra%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feffectra%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffectra%2Fcors/lists"}