PHPackages                             polymorphine/headers - 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. polymorphine/headers

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

polymorphine/headers
====================

HTTP Response headers middleware

0.1.5(1y ago)0190↑650%MITPHPPHP ^7.4 || ^8.0

Since Mar 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/polymorphine/headers)[ Packagist](https://packagist.org/packages/polymorphine/headers)[ RSS](/packages/polymorphine-headers/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (6)Dependencies (4)Versions (7)Used By (0)

Polymorphine/Headers
====================

[](#polymorphineheaders)

[![Latest stable release](https://camo.githubusercontent.com/e1ba432799fd5ef2db7e1e2ff4e4b078c39e55edd06924f4098dd93d2d171869/68747470733a2f2f706f7365722e707567782e6f72672f706f6c796d6f727068696e652f686561646572732f76657273696f6e)](https://packagist.org/packages/polymorphine/headers)[![Build status](https://github.com/polymorphine/headers/workflows/build/badge.svg)](https://github.com/polymorphine/headers/actions)[![Coverage status](https://camo.githubusercontent.com/ba0276bfd13a2ec3d53d620bf7b3673c78fdea1a94ec2386bc9237530978b0bb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706f6c796d6f727068696e652f686561646572732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/polymorphine/headers?branch=develop)[![PHP version](https://camo.githubusercontent.com/aeb74d3d1649875253314c765f68ffecf7104652206e7010f5653d0fd7cc3eff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f6c796d6f727068696e652f686561646572732e737667)](https://packagist.org/packages/polymorphine/headers)[![LICENSE](https://camo.githubusercontent.com/13cbf3f852f18ed7a55295523c622e091cfb2bc77b844bc9f401811bf0dc0b5d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706f6c796d6f727068696e652f686561646572732e7376673f636f6c6f723d626c7565)](LICENSE)

### HTTP Response headers middleware

[](#http-response-headers-middleware)

### Installation with [Composer](https://getcomposer.org/)

[](#installation-with-composer)

```
composer require polymorphine/headers
```

### Basic usage

[](#basic-usage)

##### *Set-Cookie header*

[](#set-cookie-header)

1. Instantiate a cookie builder using `ResponseHeaders` context: ```
    $headers     = new ResponseHeaders();
    $cookieSetup = new CookieSetup($headers);
    ```

    Alternatively, instantiating `CookieSetup` is possible with `ResponseHeaders` method: ```
    $cookieSetup = $context->cookieSetup();
    ```
2. Configure cookie with array of its directives/attributes (see [`CookieSetup::directives()`](/src/Cookie/CookieSetup.php#L51) method): ```
    $cookieSetup->directives([
        'Domain'   => 'example.com',
        'Path'     => '/admin',
        'Expires'  => new DateTime(...),
        'MaxAge'   => 1234,
        'Secure'   => true,
        'HttpOnly' => true,
        'SameSite' => 'Strict'
    ]);
    ```

    Modifying setup object is also possible with its builder methods: ```
    $cookieSetup->domain('example.com')
                ->path('/admin')
                ->expires(new DateTime(...))
                ->maxAge(1234)
                ->secure()
                ->httpOnly()
                ->sameSite('Strict');
    ```
3. Instantiate [`Cookie`](/src/Cookie.php) type object with its name: ```
    $cookie = $cookieSetup->cookie('MyCookie');
    ```
4. Send value: ```
    $cookie->send('value');
    ```

    or order to revoke cookie, so that it should not be sent with future requests: ```
    $cookie->revoke();
    ```

    Each cookie can send/revoke header only once

##### Directives and Attributes

[](#directives-and-attributes)

Directives are used according to [RFC6265](https://tools.ietf.org/html/rfc6265#section-4.1.2)section about Set-Cookie header attributes (except relatively new `SameSite` directive). Their description might also be found at [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie). Concise description with additional class logic is explained in docBlocks of mutator methods of [`CookieSetup`](src/Cookie/CookieSetup.php) class.

Here are some class-specific rules for setting those directives:

- Empty values and root path (`/`) might be omitted as they're same as default.
- `SameSite` allowed values are `Strict` or `Lax`, but `Lax` will be set for any non-empty value given.
- `Expires` and `MaxAge` are different ways to set the same cookie's expiry date. If both directives will be passed into constructor or `directivesArray()` method, last value will be used due to overwrite.

##### Cookie with predefined directives

[](#cookie-with-predefined-directives)

`CookieSetup` has two alternative methods creating `Cookie` instance: `CookieSetup::permanentCookie()` and `CookieSetup::sessionCookie()`.

- *Permanent* constructor sets long (5 years) expiry values (`Expires` and `MaxAge`)
- *Session* constructor sets security directives (`HttpOnly` and `SameSite=Lax`)

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance45

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~284 days

Recently: every ~225 days

Total

6

Last Release

465d ago

PHP version history (2 changes)0.1.0PHP ^7.4

0.1.1PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b83b30083b2ca0951558f0516ded598877c690f2be60cf949d9be3fdf0389ca?d=identicon)[shudd3r](/maintainers/shudd3r)

---

Top Contributors

[![shudd3r](https://avatars.githubusercontent.com/u/9908030?v=4)](https://github.com/shudd3r "shudd3r (55 commits)")

---

Tags

httppsr-15psr-7

### Embed Badge

![Health badge](/badges/polymorphine-headers/health.svg)

```
[![Health](https://phpackages.com/badges/polymorphine-headers/health.svg)](https://phpackages.com/packages/polymorphine-headers)
```

###  Alternatives

[relay/relay

A PSR-15 server request handler.

3302.1M85](/packages/relay-relay)[neos/flow

Flow Application Framework

862.0M448](/packages/neos-flow)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[openswoole/core

Openswoole core library

181.1M31](/packages/openswoole-core)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jimtools/jwt-auth

PSR-15 JWT Authentication middleware, A replacement for tuupola/slim-jwt-auth

20142.3k3](/packages/jimtools-jwt-auth)

PHPackages © 2026

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