Skip to content

bolint/silex-cors-provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silex-cors-provider

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 "~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 JDesrosiers\Silex\Provider\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 its scope.

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

About

A silex service provider that adds CORS services to silex

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%