PHPackages                             ronanchilvers/silex-middleware - 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. ronanchilvers/silex-middleware

ActiveLibrary

ronanchilvers/silex-middleware
==============================

Some useful middleware for silex

1.3(7y ago)1939MITPHP

Since Jan 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ronanchilvers/silex-middleware)[ Packagist](https://packagist.org/packages/ronanchilvers/silex-middleware)[ RSS](/packages/ronanchilvers-silex-middleware/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

silex-middleware
================

[](#silex-middleware)

A collection of middleware for use with Silex.

Installation
------------

[](#installation)

```
composer require ronanchilvers/silex-middleware
```

Configuration
-------------

[](#configuration)

Configuration details varies depending on the middleware in use. See the notes below for specifics.

Available Middlewares
---------------------

[](#available-middlewares)

- [Content Security Policy](#content-security-policy)
- [Referrer Policy](#referrer-policy)
- [Strict Transport Security](#strict-transport-security)

### Content Security Policy

[](#content-security-policy)

This middleware allows you to add a Content-Security-Policy header to responses. It uses the [`paragonie/csp-builder`](https://github.com/paragonie/csp-builder) library to build the headers. You can pass your policy as an array as the first constructor argument.

```
$app->after(
    new Ronanchilvers\Silex\Middleware\ContentSecurityPolicy([
        'default-src' => [
            'self' => true,
            'unsafe-inline' => true,
        ],
        'style-src' => [
            'allow' => [
                'https://fonts.googleapis.com'
            ],
            'self' => true,
            'unsafe-inline' => true,
        ],
        'font-src' => [
            'allow' => [
                'https://fonts.gstatic.com/'
            ],
            'self' => true
        ],
        'report-only' => true,
    ])
);
```

### Referrer Policy

[](#referrer-policy)

This middleware adds a [Referrer-Policy](https://www.w3.org/TR/referrer-policy/) header to responses. This header has a single policy directive as its value which must be one of:

- &lt;empty string&gt;
- no-referrer
- no-referrer-when-downgrade
- same-origin
- origin
- strict-origin
- origin-when-cross-origin
- strict-origin-when-cross-origin
- unsafe-url

The exact meaning of each of these is explained [in this blog post by Scott Helme](https://scotthelme.co.uk/a-new-security-header-referrer-policy/) as well as [on the w3.org official specification](https://www.w3.org/TR/referrer-policy/#referrer-policies).

```
// This adds the middleware with a default 'no-referrer' policy
$app->after(new Ronanchilvers\Silex\ReferrerPolicy());

// This specifies the 'strict-origin' policy
$app->after(new Ronanchilvers\Silex\ReferrerPolicy('strict-origin'));
```

### Strict Transport Security

[](#strict-transport-security)

This middleware adds [HSTS or Strict Transport Security](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) headers to every response.

```
// Add with defaults
$app->after(new Ronanchilvers\Silex\Middleware\StrictTransportSecurity());

// Or - set the max-age to 1 day / 86400 seconds
$app->after(new Ronanchilvers\Silex\Middleware\StrictTransportSecurity(86400));
```

The middleware accepts two constructor arguments:

- Max age in seconds - defaults to 15552000 seconds or 6 months
- Include sub domains - defaults to false

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~120 days

Total

4

Last Release

2675d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f6d7178329cb95270cfb9c807c3d2a6485d0f856c3d81cfe432e469e5f958748?d=identicon)[ronanchilvers](/maintainers/ronanchilvers)

---

Top Contributors

[![ronanchilvers](https://avatars.githubusercontent.com/u/87890?v=4)](https://github.com/ronanchilvers "ronanchilvers (11 commits)")

### Embed Badge

![Health badge](/badges/ronanchilvers-silex-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/ronanchilvers-silex-middleware/health.svg)](https://phpackages.com/packages/ronanchilvers-silex-middleware)
```

###  Alternatives

[stikmanw/silex-newrelic

Integrate the NewRelic PHP API into Silex framework

2014.7k](/packages/stikmanw-silex-newrelic)

PHPackages © 2026

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