2017 © Pedro Peláez
 

library corsslim

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

image

palanik/corsslim

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

  • Sunday, October 2, 2016
  • by palanik
  • Repository
  • 9 Watchers
  • 85 Stars
  • 116,664 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 16 Forks
  • 4 Open issues
  • 11 Versions
  • 14 % Grown

The README.md

CorsSlim

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

Latest Stable Version Build Status License, (*2)

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

add(new \CorsSlim\CorsSlim());
?>

Custom Load

add(new \CorsSlim\CorsSlim());
?>

Options

You can create the middleware with custom options. Pass options as associative array. * origin => The value to set for Access-Control-Allow-Origin response header. Default value is '*'. * exposeHeaders => The value to set for Access-Control-Expose-Headers response header. Pass an array of strings. * maxAge => The value to set for Access-Control-Max-Age response header. * allowCredentials => The value to set for Access-Control-Allow-Credentials response header. Pass True/False. * allowMethods => The value to set for Access-Control-Allow-Methods response header. Pass an array of allowed method names. Default values are GET,HEAD,PUT,POST,DELETE. * allowHeaders => The value to set for Access-Control-Allow-Headers response header. Pass an array of allowed headers., (*3)

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., (*4)

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., (*5)

Use the static method routeMiddleware to create and add cors middleware to specific routes., (*6)

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

Also with custom options., (*7)

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

?>

For Preflighted requests, provide OPTIONS implementation for the corresponding routes., (*8)

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

?>

License

MIT, (*9)

The Versions

02/10 2016

dev-master

9999999-dev https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

15/01 2016

dev-slim3

dev-slim3 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

20/12 2015

dev-dev

dev-dev https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

20/12 2015

dev-slim-v2

dev-slim-v2 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

17/12 2015

v1.1.0

1.1.0.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

19/11 2015

v1.0.0

1.0.0.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

29/04 2015

v0.0.5

0.0.5.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

15/04 2015

v0.0.4

0.0.4.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

10/02 2015

v0.0.3

0.0.3.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin preflight corsslim

10/02 2015

v0.0.2

0.0.2.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin corsslim

26/10 2014

v0.0.1

0.0.1.0 https://github.com/palanik/CorsSlim

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

  Sources   Download

MIT

The Requires

 

by Avatar palanik

cors slim slimphp cross-origin corsslim