zozlak/http-accept

Set of methods to deal with the HTTP Accept header

Maintainers

πŸ‘ zozlak

Package info

github.com/zozlak/httpAccept

pkg:composer/zozlak/http-accept

Statistics

Installs: 9 316

Dependents: 5

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.0 2026-02-17 13:15 UTC

Requires

  • php: >=8.1

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d2494e8d56a2ceb15f7de9484da73c43f44b1539

  • Mateusz Ε»Γ³Ε‚tak <zozlak.woop@zozlak.org>

This package is auto-updated.

Last update: 2026-06-17 14:22:16 UTC


README

πŸ‘ Latest Stable Version
πŸ‘ Build status
πŸ‘ Coverage Status
πŸ‘ License

HttpAccept

A static class making it easier to deal with the HTTP Accept header.

Can be also used to deal with other HTTP headers which provide multiple options with weights, e.g. the Accept-Encoding one.

installation

composer require zozlak/http-accept

usage

// Simplest use - parse the HTTP Accept header
// e.g. for an Accept header of
// text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
// the result is `application/xml;q=0.9`
$header = zozlak\httpAccept\Accept::fromHeader();
$bestMatch = $header->getBestMatch(['application/json', 'application/xml']);
echo (string) $bestMatch . "\n";

// Deal with Accept-Encoding
$header = zozlak\httpAccept\Accept::fromHeader('accept-encoding');
try {
 $bestMatch = $header->getBestMatch(['deflate']);
} catch (zozlak\httpAccept\NoMatchException) {
 $bestMatch = new zozlak\httpAccept\Format('identity');
}
echo $bestMatch->type . "\n";

// Check if two formats match
$format1 = zozlak\httpAccept\Format::fromString('application/xml');
$format2 = new zozlak\httpAccept\Format('application', '*');
var_dump($format1->matches($format2));