承接 jdesrosiers/silex-cors-provider 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jdesrosiers/silex-cors-provider

最新稳定版本:v1.6.1

Composer 安装命令:

composer require jdesrosiers/silex-cors-provider

包简介

A silex service provider that adds CORS services to silex

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

The CorsServiceProvider provides CORS support as middleware for your silex application. CORS allows you to make AJAX requests across domains. CORS uses OPTIONS requests to make preflight requests. Because silex doesn't have functionality for serving OPTIONS request by default, this service goes through all of your routes and generates the necessary OPTIONS routes.

Installation

Install the silex-cors-provider using composer. This project uses sematic versioning.

composer require jdesrosiers/silex-cors-provider "~1.0"

Parameters

  • cors.allowOrigin: (string) Space separated set of allowed domains (wildcards allowed e.g. http://*.example.com). Defaults to all.
  • cors.allowMethods: (string) Comma separated set of allowed HTTP methods. Defaults to all.
  • cors.allowHeaders: (string) Comma separated set of allowed HTTP request headers. Defaults to all.
  • cors.maxAge: (int) The number of seconds a CORS pre-flight response can be cached. Defaults to 0.
  • cors.allowCredentials: (boolean) Are cookies allowed? Defaults to false.
  • cors.exposeHeaders: (string) Comma separated set of headers that are safe to expose. Defaults to none. This should not include the six simple response headers which are always exposed: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma.

Services

  • cors: A function that can be added as after middleware to the Application. (Deprecated. Use cors-enabled instead)
  • cors-enabled: Pass this function an Application, a ControllerCollection, or a Controller and it will enable CORS support for every route the object defines. Optionally, you can pass an array of options as a second parameter. The options you can pass are the same as the cors.* parameters without the cors. part. This is useful of you need different configuration for different routes.
  • options: Similar to cors-enabled but only creates OPTIONS routes with no CORS support.
  • allow: A function that can be added as after middleware to an Application, a ControllerCollection, or a Controller that will add an Allow header to every route the object defines.

Registering

$app->register(new JDesrosiers\Silex\Provider\CorsServiceProvider(), [
    "cors.allowOrigin" => "http://petstore.swagger.wordnik.com",
]);

Usage

Add CORS functionality to the entire application.

$app->get("/foo/{id}", function ($id) { /* ... */ });
$app->post("/foo/", function () { /* ... */ });

$app["cors-enabled"]($app);

Add CORS functionality to a controller collection.

$foo = $app["controllers_factory"];
$foo->get("/{id}", function () { /* ... */ });
$foo->post("/", function () { /* ... */ });
$app->mount("/foo", $app["cors-enabled"]($foo));

$app->get("/bar/{id}", function ($id) { /* ... */ }); // Not CORS enabled

Add CORS functionality to a controller.

$controller = $app->get("/foo/{id}", function ($id) { /* ... */ });
$app["cors-enabled"]($controller);
$app->post("/foo/", function () { /* ... */ }); // Not CORS enabled

统计信息

  • 总下载量: 881.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 83
  • 点击次数: 3
  • 依赖项目数: 13
  • 推荐数: 0

GitHub 信息

  • Stars: 79
  • Watchers: 7
  • Forks: 25
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固