定制 palanik/corsslim 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

palanik/corsslim

最新稳定版本:v1.1.0

Composer 安装命令:

composer require palanik/corsslim

包简介

Cross-origin resource sharing (CORS) middleware for PHP Slim.

README 文档

README

Cross-origin resource sharing (CORS) Middleware for PHP Slim Framework.

Latest Stable Version Build Status License

Usage

Composer Autoloader

Install with Composer

  1. Update your composer.json to require palanik/corsslim package.
  2. Run composer install to add CorsSlim your vendor folder.
{
  "require": {
    "palanik/corsslim": "*"
  }
}

Autoloading

<?php
require ('./vendor/autoload.php');

$app = new \Slim\Slim();

$app->add(new \CorsSlim\CorsSlim());
?>

Custom Load

<?php
\Slim\Slim::registerAutoLoader();

$app = new \Slim\Slim();

require ('path_to_your_middlewares/CorsSlim.php');
$app->add(new \CorsSlim\CorsSlim());
?>

Options

You can create the middleware with custom options. Pass options as associative array.

Example

$corsOptions = array(
    "origin" => "*",
    "exposeHeaders" => array("X-My-Custom-Header", "X-Another-Custom-Header"),
    "maxAge" => 1728000,
    "allowCredentials" => True,
    "allowMethods" => array("POST, GET"),
    "allowHeaders" => array("X-PINGOTHER")
    );
$cors = new \CorsSlim\CorsSlim($corsOptions);

Whitelisted Origins

Set an array of allowed origins to origin option. If a matching request origin found it is used.

Example

$corsOptions = array(
    "origin" => array('http://one.allowed-origin.com', 'http://two.allowed-origin.com'),
    "exposeHeaders" => array("X-My-Custom-Header", "X-Another-Custom-Header"),
    "maxAge" => 1728000,
    "allowCredentials" => True,
    "allowMethods" => array("POST, GET"),
    "allowHeaders" => array("X-PINGOTHER")
    );
$cors = new \CorsSlim\CorsSlim($corsOptions);

Route Middleware

New

You can now enable cors selectively for individual routes.

Use the static method routeMiddleware to create and add cors middleware to specific routes.

<?php
require ('./vendor/autoload.php');
$app = new \Slim\Slim();

$app->get('/item/:id', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {
            ...
          }
        );
?>

Also with custom options.

<?php
require ('./vendor/autoload.php');
$app = new \Slim\Slim();

$corsOptions = array("origin" => "*");
$app->get('/item/:id', 
          \CorsSlim\CorsSlim::routeMiddleware($corsOptions), 
          function ($name) use ($app) {
            ...
          }
        );

?>

For Preflighted requests, provide OPTIONS implementation for the corresponding routes.

<?php
require ('./vendor/autoload.php');
$app = new \Slim\Slim();

$app->options('/item', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {}
        );
$app->post('/item', 
          \CorsSlim\CorsSlim::routeMiddleware(), 
          function ($name) use ($app) {
            ...
          }
        );

?>

License

MIT

统计信息

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

GitHub 信息

  • Stars: 93
  • Watchers: 8
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固