{"id":13704188,"url":"https://github.com/medz/cors","last_synced_at":"2025-10-01T02:31:28.353Z","repository":{"id":44463168,"uuid":"125001413","full_name":"medz/cors","owner":"medz","description":"🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.","archived":true,"fork":false,"pushed_at":"2020-05-09T16:09:08.000Z","size":98,"stargazers_count":274,"open_issues_count":2,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-09-23T22:02:30.350Z","etag":null,"topics":["cors","cors-middleware","cors-request","crossdomain","laravel","laravel5","middleware","php","php-cors","psr-15","psr-7","request","response","slim","swoft","symfony","thinkphp","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/medz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["medz"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-03-13T06:12:28.000Z","updated_at":"2024-02-14T10:25:31.000Z","dependencies_parsed_at":"2022-08-03T02:45:54.775Z","dependency_job_id":null,"html_url":"https://github.com/medz/cors","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/medz","download_url":"https://codeload.github.com/medz/cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875269,"owners_count":16554661,"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":["cors","cors-middleware","cors-request","crossdomain","laravel","laravel5","middleware","php","php-cors","psr-15","psr-7","request","response","slim","swoft","symfony","thinkphp","yii2"],"created_at":"2024-08-02T21:01:05.371Z","updated_at":"2025-10-01T02:31:23.023Z","avatar_url":"https://github.com/medz.png","language":"PHP","funding_links":["https://github.com/sponsors/medz"],"categories":["PHP","目录","HTTP","类库"],"sub_categories":["HTTP客户端 HTTP Client","未归类"],"readme":"# CORS\n\n![PHP Composer](https://github.com/medz/cors/workflows/PHP%20Composer/badge.svg)\n[![StyleCI](https://styleci.io/repos/125001413/shield?branch=master)](https://styleci.io/repos/125001413)\n[![Build Status](https://travis-ci.org/medz/cors.svg?branch=master)](https://travis-ci.org/medz/cors)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmedz%2Fcors.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmedz%2Fcors?ref=badge_shield)\n\nPHP CORS (Cross-origin resource sharing) middleware.\n\n## Support\n\n- [x] [Array, Coding in Native PHP](#array)\n- [x] [Using PSR-7](#psr-7)\n- [x] [PSR-15 Support](https://github.com/medz/cors/blob/master/docs/psr-15-support.md)\n- [ ] Symfony Support\n- [x] [Laravel Support](https://github.com/medz/cors/blob/master/docs/using-by-laravel.md)\n- [x] [Lumen Support](https://github.com/medz/cors/blob/master/docs/using-by-lumen.md)\n- [ ] Yii2 Support\n- [x] [Swoft Framework](https://github.com/medz/cors/blob/master/docs/using-by-swoft.md)\n- [x] [Slim Framework](https://github.com/medz/cors/blob/master/docs/using-by-slim.md)\n- [x] [ThinkPHP Support](https://github.com/medz/cors/blob/master/docs/using-by-thinkphp.md)\n\n## Using\n\n```shell\ncomposer require medz/cors\n```\n\nExample:\n\n```php\nuse Medz\\Cors\\Cors;\n\n$cors = new Cors($config); // The $config 👉 `config/cors.php` file.\n$cors-\u003esetRequest($requestType, $request); // The $request is empty array or is `NULL` or $_REQUEST\n$cors-\u003esetResponse($responseType, $response); // The $response is empty array.\n$cors-\u003ehandle();\n\n$response = $cors-\u003egetResponse();\n```\n\nBoth `$requestType` and `$responseType` are of any type that is individually set to support, but if used in a framework, these two values are usually the same. Because you can set it up individually, you can deliver different values depending on your needs to achieve your goals.\n\n### Configure\n\nThe config example:\n\n```php\n$config = [\n    'allow-credentials' =\u003e false, // set \"Access-Control-Allow-Credentials\" 👉 string \"false\" or \"true\".\n    'allow-headers'      =\u003e ['*'], // ex: Content-Type, Accept, X-Requested-With\n    'expose-headers'     =\u003e [],\n    'origins'            =\u003e ['*'], // ex: http://localhost\n    'methods'            =\u003e ['*'], // ex: GET, POST, PUT, PATCH, DELETE\n    'max-age'            =\u003e 0,\n];\n```\n\n### Array\n\n```php\nuse Medz\\Cors\\Cors;\n\n$cors = new Cors($config);\n$cors-\u003esetRequest('array', $request);\n$cors-\u003esetResponse('array', $response);\n$cors-\u003ehandle();\n\n$responseHeadersArray = $cors-\u003egetResponse();\n```\n\n### PSR-7\n\n```php\nuse Medz\\Cors\\Cors;\n\n$cors = new Cors($config);\n$cors-\u003esetRequest('psr-7', $request);\n$cors-\u003esetResponse('psr-7', $response);\n\n$response = $cors-\u003egetResponse();\n```\n\n### Other\n\nBecause of the interface features provided by this package, you can implement it in a small amount of code in any other framework.\n\n### Excellent Repositories\n\n- [ThinkSNS+](https://github.com/slimkit/thinksns-plus) A strong community system\n\n## License\n\nThe component is open-sourced software licensed under the [MIT license](https://github.com/medz/cors/blob/master/LICENSE).\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmedz%2Fcors.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmedz%2Fcors?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedz%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmedz%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedz%2Fcors/lists"}