camilord/php-cors
Composer 安装命令:
composer require camilord/php-cors
包简介
Cross-origin resource sharing library for the Symfony HttpFoundation
README 文档
README
Library and middleware enabling cross-origin resource sharing for your http-{foundation,kernel} using application. It attempts to implement the W3C Recommendation for cross-origin resource sharing.
Note: This is a standalone fork of https://github.com/asm89/stack-cors and is compatible with the options for CorsService.
Installation
Require fruitcake/php-cors using composer.
Usage
This package can be used as a library. You can use it in your framework using:
- Stack middleware: https://github.com/asm89/stack-cors
- Laravel: https://github.com/fruitcake/laravel-cors
Options
| Option | Description | Default value |
|---|---|---|
| allowedMethods | Matches the request method. | [] |
| allowedOrigins | Matches the request origin. | [] |
| allowedOriginsPatterns | Matches the request origin with preg_match. |
[] |
| allowedHeaders | Sets the Access-Control-Allow-Headers response header. | [] |
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | [] |
| maxAge | Sets the Access-Control-Max-Age response header. | 0 |
| supportsCredentials | Sets the Access-Control-Allow-Credentials header. | 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. A wildcard in allowedOrigins will be converted to a pattern.
If ['*'] is provided to allowedMethods, allowedOrigins or allowedHeaders all methods / origins / headers are allowed.
Note: Allowing a single static origin will improve cacheability.
Example: using the library
<?php use Fruitcake\Cors\CorsService; $cors = new CorsService([ 'allowedHeaders' => ['x-allowed-header', 'x-other-allowed-header'], 'allowedMethods' => ['DELETE', 'GET', 'POST', 'PUT'], 'allowedOrigins' => ['http://localhost', 'https://*.example.com'], 'allowedOriginsPatterns' => ['/localhost:\d/'], 'exposedHeaders' => ['Content-Encoding'], 'maxAge' => 0, 'supportsCredentials' => false, ]); $cors->addActualRequestHeaders(Response $response, $origin); $cors->handlePreflightRequest(Request $request); $cors->isActualRequestAllowed(Request $request); $cors->isCorsRequest(Request $request); $cors->isPreflightRequest(Request $request);
License
Released under the MIT License, see LICENSE.
This package is split-off from https://github.com/asm89/stack-cors and developed as stand-alone library since 2022
camilord/php-cors 适用场景与选型建议
camilord/php-cors 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.06k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「cors」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 camilord/php-cors 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 camilord/php-cors 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 camilord/php-cors 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
Allows multi origin HTTP requests (CORS) supports
A simple proxy service for performing cross-domain AJAX requests.
Alfabank REST API integration
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-09