PHPackages                             ejetar/accept-header-interpreter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ejetar/accept-header-interpreter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ejetar/accept-header-interpreter
================================

Accept Header toolbox 🧰 to Laravel. Validation and interpretation based on RFC 7231, section 5.3.1 and 5.3.2. Conversion of the list of media types to ordered Laravel Collections (by priority, according to RFC).

1.1.0-alpha(6y ago)420MITPHPPHP &gt;=7.2.5CI failing

Since Nov 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ejetar/accept-header-interpreter)[ Packagist](https://packagist.org/packages/ejetar/accept-header-interpreter)[ Docs](https://ejetar.com/projects/accept-header-interpreter)[ RSS](/packages/ejetar-accept-header-interpreter/feed)WikiDiscussions master Synced 2d ago

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

Accept Header Interpreter
=========================

[](#accept-header-interpreter)

Table of Contents
-----------------

[](#table-of-contents)

- [About](#about)
- [Features](#features)
- [Installation](#installation)
- [Examples](#examples)
    - [First Example: Entering *valid* content](#first-example--entering--valid--content)
    - [Second Example: Entering *invalid* content](#second-example--entering--invalid--content)
    - [Third Example: Priority](#third-example--priority)
    - [Fourth Example: Displaying the original content of the Accept Header](#fourth-example--displaying-the-original-content-of-the-accept-header)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)

About
-----

[](#about)

Accept Header toolbox 🧰 to **Laravel**. Validation and interpretation based on **RFC 7231, section 5.3.1 and 5.3.2**. Conversion of the list of media types to ordered Laravel Collections (by priority, according to RFC).

Features
--------

[](#features)

- Validation: Validates if Accept Header content is valid, according to specification;
- Conversion: Converts the list of media types to a Laravel Collection (automatically sorted by priority according to specification);

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

[](#installation)

`composer require ejetar/accept-header-interpreter`

Examples
--------

[](#examples)

### First Example: Entering *valid* content

[](#first-example-entering-valid-content)

```
use Ejetar\AcceptHeaderInterpreter\AcceptHeaderInterpreter;

try {
  $content = request()->headers->get('Accept'); //return accept header content
  //let's assume that $content is now: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

  $acceptHeaderInterpreter = new AcceptHeaderInterpreter($content);
  dd($acceptHeaderInterpreter->toCollection());

} catch (\Exception $ex) {
  echo $ex->getMessage();
}

/* the code above will print
Collection {#756 ▼
  #items: array:6 [▼
    0 => array:3 [▼
      "type" => "text"
      "subtype" => "html"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    1 => array:3 [▼
      "type" => "application"
      "subtype" => "xhtml+xml"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    3 => array:3 [▼
      "type" => "image"
      "subtype" => "webp"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    4 => array:3 [▼
      "type" => "image"
      "subtype" => "apng"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    2 => array:3 [▼
      "type" => "application"
      "subtype" => "xml"
      "parameters" => array:1 [▼
        "q" => "0.9"
      ]
    ]
    5 => array:3 [▼
      "type" => "*"
      "subtype" => "*"
      "parameters" => array:1 [▼
        "q" => "0.8"
      ]
    ]
  ]
}

REALIZE THAT THE ORDER OF MEDIA TYPES HAS BEEN MODIFIED
*/
```

### Second Example: Entering *invalid* content

[](#second-example-entering-invalid-content)

```
use Ejetar\AcceptHeaderInterpreter\AcceptHeaderInterpreter;

try {
  $content = request()->headers->get('Accept'); //return accept header content
  //let's assume that $content is now: text/html,application/xhtml+xml,application/xml;q=1.1,image/webp,image/apng,*/*;q=0.8
  //It is only allowed to inform values from 0 to 1 for the parameter Q, that is, the contents of this Accept Header is invalid

  $acceptHeaderInterpreter = new AcceptHeaderInterpreter($content);
  dd($acceptHeaderInterpreter->toCollection());

} catch (\Exception $ex) {
  echo $ex->getMessage();
}

/* the code above will print
Accept header value is invalid!
*/
```

### Third Example: Priority

[](#third-example-priority)

```
use Ejetar\AcceptHeaderInterpreter\AcceptHeaderInterpreter;

try {
  $content = request()->headers->get('Accept'); //return accept header content
  //let's assume that $content is now: */*, application/*, text/html, application/xhtml+xml

  $acceptHeaderInterpreter = new AcceptHeaderInterpreter($content);
  dd($acceptHeaderInterpreter->toCollection());

} catch (\Exception $ex) {
  echo $ex->getMessage();
}

/* the code above will print
Collection {#756 ▼
  #items: array:4 [▼
    2 => array:3 [▼
      "type" => " text"
      "subtype" => "html"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    3 => array:3 [▼
      "type" => " application"
      "subtype" => "xhtml+xml"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    1 => array:3 [▼
      "type" => " application"
      "subtype" => "*"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
    0 => array:3 [▼
      "type" => "*"
      "subtype" => "*"
      "parameters" => array:1 [▼
        "q" => 1
      ]
    ]
  ]
}

NOTE THAT ORDER OF THE MEDIA TYPES IS NO LONGER THE SAME, IT WAS MODIFIED AS A PRIORITY, ACCORDING TO THE SPECIFICATION.
*/
```

### Fourth Example: Displaying the original content of the Accept Header

[](#fourth-example-displaying-the-original-content-of-the-accept-header)

```
use Ejetar\AcceptHeaderInterpreter\AcceptHeaderInterpreter;

try {
  $content = request()->headers->get('Accept'); //return accept header content
  //let's assume that $content is now: application/json

  $acceptHeaderInterpreter = new AcceptHeaderInterpreter($content);
  echo $acceptHeaderInterpreter->getOriginalContent();

} catch (\Exception $ex) {
  echo $ex->getMessage();
}

/* the code above will print
application/json
*/
```

Changelog
---------

[](#changelog)

Nothing for now...

Contributing
------------

[](#contributing)

Contribute to this wonderful project, it will be a pleasure to have you with us. Let's help the free software community. You are invited to incorporate new features, make corrections, report bugs, and any other form of support. Don't forget to star in this repository! 😀

License
-------

[](#license)

This library is a open-source software licensed under the MIT license.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

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

Total

2

Last Release

2231d ago

PHP version history (2 changes)1.0.0-alphaPHP &gt;=5.4.0

1.1.0-alphaPHP &gt;=7.2.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/781358602863d7536e95494388bda4d9f53175fdf5029d9db7b45d4eabef10e9?d=identicon)[ejetar](/maintainers/ejetar)

![](https://www.gravatar.com/avatar/0f38f3cc45c3861823f86149c7dcad812185a96fcfc57fb6bc00de1a4fe773b3?d=identicon)[guilhermeagirardi](/maintainers/guilhermeagirardi)

---

Top Contributors

[![ggirardi1](https://avatars.githubusercontent.com/u/2306117?v=4)](https://github.com/ggirardi1 "ggirardi1 (7 commits)")

---

Tags

accept-headerinterpretationinterpreterlaravelphprfc-7231phplaravelaccept header

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ejetar-accept-header-interpreter/health.svg)

```
[![Health](https://phpackages.com/badges/ejetar-accept-header-interpreter/health.svg)](https://phpackages.com/packages/ejetar-accept-header-interpreter)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[mediconesystems/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

1.2k711.3k8](/packages/mediconesystems-livewire-datatables)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

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