Skip to content

EdwardIII/silex-cors-provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silex-cors-provider

Gittip Build Status Scrutinizer Quality Score Code Coverage

The CorsServiceProvider provides CORS support as middleware for your silex application. CORS allows you to make AJAX requests accross domains. CORS uses OPTIONS requests to make prefight requests. Because silex doesn't have functionaily 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 "~0.1"

Parameters

  • cors.allowOrigin: (string) Space separated set of allowed domains. Defaults to all.
  • cors.allowMethods: (string) Comma separated set of allowed HTTP methods. 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) Space separated set of headers that are safe to expose. Defaults to all.

Services

  • cors: A function that can be added as after middleware to the Application, a ControllerCollection, or a Route.

Registering

$app->register(new CorsServiceProvider(), array(
    "cors.allowOrigin" => "http://petstore.swagger.wordnik.com",
));

Usage

The following shows how to add CORS functionality to the entire application. It can also be applied to a ControllerCollection a Route to limit it's scope.

$app->after($app["cors"]);

About

A Silex 1.2 compatible service provider that adds CORS services

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%