compwright/psr-cors 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

compwright/psr-cors

最新稳定版本:v1.0.0

Composer 安装命令:

composer require compwright/psr-cors

包简介

PHP interop cross-origin resource sharing (CORS) library and middleware

README 文档

README

Library and middleware enabling cross-origin resource sharing (CORS) for your PHP interoperable application, utilizing the PSR-7 and PSR-15 standards.

It attempts to implement the W3C Recommendation for cross-origin resource sharing.

Build status: .github/workflows/run-tests.yml

Installation

Require compwright/psr-cors using composer.

Usage

This package can be used as a library or as PSR-15 middleware.

Options

Option Description Default value
allowedMethods Matches the request method. All
allowedOrigins Matches the request origin (supports regex). All
allowedHeaders Sets the Access-Control-Allow-Headers response header. All
exposedHeaders Sets the Access-Control-Expose-Headers response header. None
maxAge Sets the Access-Control-Max-Age response header. Set to null to omit the header/use browser default. None
supportsCredentials Sets the Access-Control-Allow-Credentials header. None

The allowedMethods and allowedHeaders options are case-insensitive.

If true is provided to allowedMethods, allowedOrigins or allowedHeaders all methods/origins/headers are allowed.

If supportsCredentials is true, you must explicitly set allowedHeaders for any headers which are not CORS safelisted.

Example: using middleware

<?php use Compwright\PsrCors\Middleware; $middleware = Middleware::create( responseFactory: $psrResponseFactory, allowedHeaders: ['x-allowed-header', 'x-other-allowed-header'], allowedMethods: ['DELETE', 'GET', 'POST', 'PUT'], allowedOrigins: ['localhost'], exposedHeaders: [], maxAge: 600, supportsCredentials: false ); $response = $middleware->handle($request, $app);

统计信息

  • 总下载量: 2.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 60
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固