mehmetik/cors
Composer 安装命令:
composer require mehmetik/cors
包简介
The `CorsSupport` class is a library for managing cross-origin resource sharing (CORS) and a middleware that operates on HTTP requests and responses in a stack application.
README 文档
README
This package provides a library and stack middleware for handling Cross-Origin Resource Sharing (CORS) in a Stack application.
Installation
To install the package, require it through Composer.
composer require mehmetik/cors
Usage
This package can be used as a library or as stack middleware.
Options
| Option | Description | Type | Default value |
|---|---|---|---|
| allowedMethods | Matches the request method. | string[] |
[] |
| allowedOrigins | Matches the request origin. | string[] |
[] |
| allowedOriginsPatterns | Matches the request origin with preg_match. |
string[] |
[] |
| allowedHeaders | Sets the Access-Control-Allow-Headers response header. | string[] |
[] |
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | string[] |
[] |
| maxAge | Sets the Access-Control-Max-Age response header. | int |
false |
| supportsCredentials | Sets the Access-Control-Allow-Credentials header. | bool |
false |
The allowedMethods and allowedHeaders options are case-insensitive.
You don't need to provide both allowedOrigins and allowedOriginsPatterns. If one of the strings passed matches, it is considered a valid origin.
If ['*'] is provided to allowedMethods, allowedOrigins or allowedHeaders all methods / origins / headers are allowed.
Example: using the library
<?php use mehmetik\Cors\CorsSupport; $cors = new CorsSupport([ 'allowedHeaders' => ['x-allowed-header', 'x-other-allowed-header'], 'allowedMethods' => ['DELETE', 'GET', 'POST', 'PUT'], 'allowedOrigins' => ['http://localhost'], 'allowedOriginsPatterns' => ['/localhost:\d/'], 'exposedHeaders' => false, 'maxAge' => false, 'supportsCredentials' => false, ]); $cors->addActualRequestHeaders(Response $response, $origin); $cors->handlePreflightRequest(Request $request); $cors->isActualRequestAllowed(Request $request); $cors->isCorsRequest(Request $request); $cors->isPreflightRequest(Request $request);
Example: using the stack middleware
<?php use mehmetik\Cors\Cors; $app = new Stack\Builder(); $app->push(new Cors($app, [ 'allowedHeaders' => ['x-allowed-header', 'x-other-allowed-header'], 'allowedMethods' => ['DELETE', 'GET', 'POST', 'PUT'], 'allowedOrigins' => ['http://localhost'], 'allowedOriginsPatterns' => ['/localhost:\d/'], 'exposedHeaders' => false, 'maxAge' => false, 'supportsCredentials' => false, ]));
License
This package is licensed under the MIT License. See the LICENSE file for details.
mehmetik/cors 适用场景与选型建议
mehmetik/cors 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cors」 「stack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mehmetik/cors 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mehmetik/cors 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mehmetik/cors 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Development and debugging tools for Recoil applications.
Allows multi origin HTTP requests (CORS) supports
A simple proxy service for performing cross-domain AJAX requests.
RESTful API server for structured and self-documenting resources over JSON, XML, ...
Cross-origin resource sharing (CORS). Add CORS middleware for Lumen micro-framework
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-27