PHPackages                             zmog/slx-cors-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. zmog/slx-cors-provider

ActiveLibrary[HTTP &amp; Networking](/categories/http)

zmog/slx-cors-provider
======================

A silex service provider that adds CORS services to silex

v2.0.1(3y ago)0718MITPHP

Since Oct 3Pushed 3y agoCompare

[ Source](https://github.com/Gizmo091/silex-cors-provider)[ Packagist](https://packagist.org/packages/zmog/slx-cors-provider)[ GitHub Sponsors](https://github.com/jdesrosiers)[ RSS](/packages/zmog-slx-cors-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (31)Used By (0)

silex-cors-provider
===================

[](#silex-cors-provider)

[![Build Status](https://camo.githubusercontent.com/7c5018ddf8ea1feaf6cfa86c413ba020be5d5e4c6b74ddce5207e41c31f7b41a/68747470733a2f2f7472617669732d63692e6f72672f6a646573726f73696572732f73696c65782d636f72732d70726f76696465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jdesrosiers/silex-cors-provider)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/58a6d69773718009cf9616a622fec32218d74189fc5fd9df01e297876787aedd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a646573726f73696572732f73696c65782d636f72732d70726f76696465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jdesrosiers/silex-cors-provider/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/ad0f8bd4433a730e3bfc799aa5341b9dadaa79a82d6b0543ec21f2bd980538d4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a646573726f73696572732f73696c65782d636f72732d70726f76696465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jdesrosiers/silex-cors-provider/?branch=master)

The CorsServiceProvider provides [CORS](http://enable-cors.org/) 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
------------

[](#installation)

Install the silex-cors-provider using [composer](http://getcomposer.org/). This project uses [sematic versioning](http://semver.org/).

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

Parameters
----------

[](#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
--------

[](#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
-----------

[](#registering)

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

Usage
-----

[](#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
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~118 days

Recently: every ~267 days

Total

30

Last Release

1167d ago

Major Versions

v0.5.0 → v1.4.12017-07-21

v0.5.1 → v1.4.22017-09-20

v0.5.2 → v1.5.02017-10-20

v0.6.0 → v1.6.02018-03-25

v0.x-dev → v2.0.02023-03-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/6045f24a5a5342628edcac98302f5ab2a6e4acfba94e79876730da54424e177d?d=identicon)[Mathieu Vedie](/maintainers/Mathieu%20Vedie)

---

Top Contributors

[![jdesrosiers](https://avatars.githubusercontent.com/u/716571?v=4)](https://github.com/jdesrosiers "jdesrosiers (51 commits)")[![Gizmo091](https://avatars.githubusercontent.com/u/289745?v=4)](https://github.com/Gizmo091 "Gizmo091 (4 commits)")[![mcuadros](https://avatars.githubusercontent.com/u/1573114?v=4)](https://github.com/mcuadros "mcuadros (3 commits)")[![adlacruzes](https://avatars.githubusercontent.com/u/31167513?v=4)](https://github.com/adlacruzes "adlacruzes (2 commits)")[![jeromemacias](https://avatars.githubusercontent.com/u/582446?v=4)](https://github.com/jeromemacias "jeromemacias (1 commits)")[![jrschumacher](https://avatars.githubusercontent.com/u/46549?v=4)](https://github.com/jrschumacher "jrschumacher (1 commits)")[![leggetter](https://avatars.githubusercontent.com/u/328367?v=4)](https://github.com/leggetter "leggetter (1 commits)")[![Macmee](https://avatars.githubusercontent.com/u/1286638?v=4)](https://github.com/Macmee "Macmee (1 commits)")[![slipo](https://avatars.githubusercontent.com/u/327999?v=4)](https://github.com/slipo "slipo (1 commits)")[![adrianbardan](https://avatars.githubusercontent.com/u/2693350?v=4)](https://github.com/adrianbardan "adrianbardan (1 commits)")[![alcalyn](https://avatars.githubusercontent.com/u/1588144?v=4)](https://github.com/alcalyn "alcalyn (1 commits)")[![cyberwolf](https://avatars.githubusercontent.com/u/95102?v=4)](https://github.com/cyberwolf "cyberwolf (1 commits)")

---

Tags

corsserviceproviderresourcesilexsharingcrossorigin

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zmog-slx-cors-provider/health.svg)

```
[![Health](https://phpackages.com/badges/zmog-slx-cors-provider/health.svg)](https://phpackages.com/packages/zmog-slx-cors-provider)
```

###  Alternatives

[jdesrosiers/silex-cors-provider

A silex service provider that adds CORS services to silex

83892.3k10](/packages/jdesrosiers-silex-cors-provider)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[ddesrosiers/silex-annotation-provider

A silex service provider that allows the use of annotations in ServiceControllers.

25246.7k3](/packages/ddesrosiers-silex-annotation-provider)[moust/silex-cache

Cache service provider for Silex application

33138.4k1](/packages/moust-silex-cache)[jdesrosiers/silex-jms-serializer-provider

A silex service provider that integrates jms/serializer into silex

11126.3k2](/packages/jdesrosiers-silex-jms-serializer-provider)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
