Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/medz/cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
https://github.com/medz/cors
cors cors-middleware cors-request crossdomain laravel laravel5 middleware php php-cors psr-15 psr-7 request response slim swoft symfony thinkphp yii2
Last synced: about 1 month ago
JSON representation
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
- Host: GitHub
- URL: https://github.com/medz/cors
- Owner: medz
- License: mit
- Archived: true
- Created: 2018-03-13T06:12:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-09T16:09:08.000Z (over 4 years ago)
- Last Synced: 2024-09-23T22:02:30.350Z (about 2 months ago)
- Topics: cors, cors-middleware, cors-request, crossdomain, laravel, laravel5, middleware, php, php-cors, psr-15, psr-7, request, response, slim, swoft, symfony, thinkphp, yii2
- Language: PHP
- Homepage:
- Size: 95.7 KB
- Stars: 274
- Watchers: 10
- Forks: 23
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- php-awesome - CORS - PHP CORS (Cross-origin resource sharing) middleware (类库 / 未归类)
- awesome-php-cn - medz/cors - PHP CORS(跨源资源共享)中间件. (目录 / HTTP客户端 HTTP Client)
README
# CORS
![PHP Composer](https://github.com/medz/cors/workflows/PHP%20Composer/badge.svg)
[![StyleCI](https://styleci.io/repos/125001413/shield?branch=master)](https://styleci.io/repos/125001413)
[![Build Status](https://travis-ci.org/medz/cors.svg?branch=master)](https://travis-ci.org/medz/cors)
[![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)PHP CORS (Cross-origin resource sharing) middleware.
## Support
- [x] [Array, Coding in Native PHP](#array)
- [x] [Using PSR-7](#psr-7)
- [x] [PSR-15 Support](https://github.com/medz/cors/blob/master/docs/psr-15-support.md)
- [ ] Symfony Support
- [x] [Laravel Support](https://github.com/medz/cors/blob/master/docs/using-by-laravel.md)
- [x] [Lumen Support](https://github.com/medz/cors/blob/master/docs/using-by-lumen.md)
- [ ] Yii2 Support
- [x] [Swoft Framework](https://github.com/medz/cors/blob/master/docs/using-by-swoft.md)
- [x] [Slim Framework](https://github.com/medz/cors/blob/master/docs/using-by-slim.md)
- [x] [ThinkPHP Support](https://github.com/medz/cors/blob/master/docs/using-by-thinkphp.md)## Using
```shell
composer require medz/cors
```Example:
```php
use Medz\Cors\Cors;$cors = new Cors($config); // The $config 👉 `config/cors.php` file.
$cors->setRequest($requestType, $request); // The $request is empty array or is `NULL` or $_REQUEST
$cors->setResponse($responseType, $response); // The $response is empty array.
$cors->handle();$response = $cors->getResponse();
```Both `$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.
### Configure
The config example:
```php
$config = [
'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
'allow-headers' => ['*'], // ex: Content-Type, Accept, X-Requested-With
'expose-headers' => [],
'origins' => ['*'], // ex: http://localhost
'methods' => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
'max-age' => 0,
];
```### Array
```php
use Medz\Cors\Cors;$cors = new Cors($config);
$cors->setRequest('array', $request);
$cors->setResponse('array', $response);
$cors->handle();$responseHeadersArray = $cors->getResponse();
```### PSR-7
```php
use Medz\Cors\Cors;$cors = new Cors($config);
$cors->setRequest('psr-7', $request);
$cors->setResponse('psr-7', $response);$response = $cors->getResponse();
```### Other
Because of the interface features provided by this package, you can implement it in a small amount of code in any other framework.
### Excellent Repositories
- [ThinkSNS+](https://github.com/slimkit/thinksns-plus) A strong community system
## License
The component is open-sourced software licensed under the [MIT license](https://github.com/medz/cors/blob/master/LICENSE).
[![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)