• Stars
    star
    1,371
  • Rank 34,304 (Top 0.7 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Content Negotiation tools for PHP.

Negotiation

GitHub Actions Total Downloads Latest Stable Version

Negotiation is a standalone library without any dependencies that allows you to implement content negotiation in your application, whatever framework you use. This library is based on RFC 7231. Negotiation is easy to use, and extensively unit tested!

Important: You are browsing the documentation of Negotiation 3.x+.

Documentation for version 1.x is available here: Negotiation 1.x documentation.

Documentation for version 2.x is available here: Negotiation 2.x documentation.

Installation

The recommended way to install Negotiation is through Composer:

$ composer require willdurand/negotiation

Usage Examples

Media Type Negotiation

$negotiator = new \Negotiation\Negotiator();

$acceptHeader = 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';
$priorities   = array('text/html; charset=UTF-8', 'application/json', 'application/xml;q=0.5');

$mediaType = $negotiator->getBest($acceptHeader, $priorities);

$value = $mediaType->getValue();
// $value == 'text/html; charset=UTF-8'

The Negotiator returns an instance of Accept, or null if negotiating the best media type has failed.

Language Negotiation

<?php

$negotiator = new \Negotiation\LanguageNegotiator();

$acceptLanguageHeader = 'en; q=0.1, fr; q=0.4, fu; q=0.9, de; q=0.2';
$priorities          = array('de', 'fu', 'en');

$bestLanguage = $negotiator->getBest($acceptLanguageHeader, $priorities);

$type = $bestLanguage->getType();
// $type == 'fu';

$quality = $bestLanguage->getQuality();
// $quality == 0.9

The LanguageNegotiator returns an instance of AcceptLanguage.

Encoding Negotiation

<?php

$negotiator = new \Negotiation\EncodingNegotiator();
$encoding   = $negotiator->getBest($acceptHeader, $priorities);

The EncodingNegotiator returns an instance of AcceptEncoding.

Charset Negotiation

<?php

$negotiator = new \Negotiation\CharsetNegotiator();

$acceptCharsetHeader = 'ISO-8859-1, UTF-8; q=0.9';
$priorities          = array('iso-8859-1;q=0.3', 'utf-8;q=0.9', 'utf-16;q=1.0');

$bestCharset = $negotiator->getBest($acceptCharsetHeader, $priorities);

$type = $bestCharset->getType();
// $type == 'utf-8';

$quality = $bestCharset->getQuality();
// $quality == 0.81

The CharsetNegotiator returns an instance of AcceptCharset.

Accept* Classes

Accept and Accept* classes share common methods such as:

  • getValue() returns the accept value (e.g. text/html; z=y; a=b; c=d)
  • getNormalizedValue() returns the value with parameters sorted (e.g. text/html; a=b; c=d; z=y)
  • getQuality() returns the quality if available (q parameter)
  • getType() returns the accept type (e.g. text/html)
  • getParameters() returns the set of parameters (excluding the q parameter if provided)
  • getParameter() allows to retrieve a given parameter by its name. Fallback to a $default (nullable) value otherwise.
  • hasParameter() indicates whether a parameter exists.

Versioning

Negotiation follows Semantic Versioning.

End Of Life

1.x

As of October 2016, branch 1.x is not supported anymore, meaning major version 1 reached end of life. Last version is: 1.5.0.

2.x

As of November 2020, branch 2.x is not supported anymore, meaning major version 2 reached end of life. Last version is: 2.3.1.

Stable Version

3.x (and dev-master)

Negotiation 3.0 has been released on November 26th, 2020. This is the current stable version and it is in sync with the main branch (a.k.a. master).

Unit Tests

Setup the test suite using Composer:

$ composer install --dev

Run it using PHPUnit:

$ phpunit

Contributing

See CONTRIBUTING file.

Credits

License

Negotiation is released under the MIT License. See the bundled LICENSE file for details.

More Repositories

1

Hateoas

A PHP library to support implementing representations for HATEOAS REST web services.
PHP
1,016
star
2

JsonpCallbackValidator

JSONP callback validator.
PHP
653
star
3

EmailReplyParser

PHP library for parsing plain text email content.
PHP
621
star
4

BazingaJsTranslationBundle

A pretty nice way to expose your Symfony translation messages to your client applications.
JavaScript
574
star
5

ArvernOS

💾 A minimal, experimental and "toy" monolithic kernel to learn about OS development // Work In Progress
C
325
star
6

BazingaHateoasBundle

Integration of the Hateoas library into Symfony.
PHP
290
star
7

BazingaFakerBundle

Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
PHP
279
star
8

docker-elk

🐳 Creating an ELK stack could not be easier.
270
star
9

nmap

nmap is a PHP wrapper for Nmap.
PHP
154
star
10

willdurand.github.io

William Durand's website ✨
HTML
147
star
11

Propilex

Silex, Propel, Backbone, Stack, Hateoas, Negotiation, and so on!
PHP
134
star
12

anchorify.js

A dead simple JavaScript library for automatically creating anchored headings in your HTML documents.
JavaScript
117
star
13

BazingaRestExtraBundle

Provides extra features for your REST APIs built using Symfony.
PHP
95
star
14

puppet-nodejs

Puppet module to manage Node.js and NPM that just works.
Ruby
69
star
15

TravisLight

A build monitoring tool (buildwall) that allows you to quickly detect failing projects for Travis-CI.
JavaScript
64
star
16

rustwasm-addon

🦀 + 🕸 + 🦊 // A web-extension to reverse a string. Yep.
JavaScript
63
star
17

StateMachineBehavior

This behavior adds a finite state machine to your model.
PHP
38
star
18

EMD

Fast and Adaptive Bidimensional Empirical Mode Decomposition Using Order-Statistics Filter Based Envelope Estimation
C++
37
star
19

dotfiles

💻 My dotfiles.
Shell
36
star
20

hubot-cachet

A hubot script to manage incidents/statuses with Cachet.
CoffeeScript
34
star
21

BazingaOAuthServerBundle

[Symfony2] A server side implementation of the OAuth 1.0 protocol based on RFC 5849.
PHP
31
star
22

puppet-composer

Puppet module to install Composer.
Ruby
30
star
23

StackNegotiation

Stack middleware for content negotiation.
PHP
27
star
24

docker-logstash-forwarder

Docker image for Logstash Forwarder, formerly known as lumberjack.
25
star
25

TypehintableBehavior

Insane Propel behavior that helps you to be compliant with third-party interfaces by adding type hint to generated methods.
PHP
22
star
26

pihole-oled

💻 Pi-hole and system stats displayed on an OLED 0.96" screen.
Python
22
star
27

jenairienacacher.fr

Site informatif autour de l'argument "je n'ai rien à cacher".
HTML
22
star
28

pman

"pear-doc.php.net/pman" on Composer/Packagist!
Shell
20
star
29

EventDispatcherBehavior

Integrates the Symfony2 EventDispatcher component in your Model classes.
PHP
19
star
30

Speaker

Speaker aims to convert my blog posts in audio files.
Shell
16
star
31

EspWiFi

Arduino driver for the ESP8266 WiFi module.
C++
15
star
32

hubot-ansible

Let Hubot run `ansible-playbook` for you!
CoffeeScript
14
star
33

sonoff-webthing

💡 An alternative firmware to create "Things" with iTead Sonoff devices.
Makefile
13
star
34

pino-devtools

🌲 A transport for viewing logs in your favorite browser devtools!
JavaScript
13
star
35

jenkins-phing-symfony

Jenkins/Phing for symfony 1.x (Works with Hudson)
12
star
36

gitlab-elk-demo

A demo project showing how to integrate Gitlab with the ELK stack.
11
star
37

dynhost

📡 Automatically update a dynamic DNS record for an OVH domain.
Rust
11
star
38

workshop-rest-from-zero-to-hero

Workshop.
PHP
10
star
39

PublishableBehavior

The PublishableBehavior is designed to quickly add publish/unpublish features to your model.
PHP
10
star
40

container-registry-proxy

📖 A proxy that makes the GitHub Container Registry compatible with the Docker Registry HTTP API V2 specification.
Go
10
star
41

BazingaPropelEventDispatcherBundle

Integrates the Propel EventDispatcherBehavior into Symfony2.
PHP
10
star
42

docker-buildtools

9
star
43

chipolata

🌭 A CHIP-8 interpreter written in Rust.
Rust
9
star
44

clermontech-workshop-git-deploy

Material for my Git Workshop.
Shell
8
star
45

cwrm

📸 WiFi Remote Module ✨ // Work In Progress
Makefile
8
star
46

containers

📦 This is a repository with some code I wrote to learn more about containers.
Go
7
star
47

gitpod-firefox-dev

Firefox development with Gitpod = ❤️
Shell
6
star
48

gameboy-breakout-board

A GameBoy card slot breakout board.
OpenSCAD
6
star
49

Karotz-Plugin

A Jenkins Plugin for my beloved Karotz.
Java
6
star
50

puppet-bazinga

A set of Puppet roles and some useful functions.
Puppet
6
star
51

thesis

📝 Automated Test Generation for production systems with a Model-based Testing approach.
TeX
6
star
52

kicad-libs

William Durand's KiCad Libraries
OpenSCAD
6
star
53

DuckHunt

A little game in haXe.
Haxe
4
star
54

isomorphic-formdata

formdata-node + browser support = <3
JavaScript
4
star
55

StateMachineExporter

Generate a Graphviz compatible file (.dot file) from a Propel XML schema, and the StateMachineBehavior.
PHP
3
star
56

demo-pretty-printer

A demo project to complement my blog post about Pretty Printers.
JavaScript
3
star
57

amo-info

🦊 An extension to show information about AMO related services.
JavaScript
3
star
58

hardware-hacking-cast-device

Tools and design files related to my research on a cheap "cast device" clone.
C
3
star
59

uberdex

The official Uberdex!
2
star
60

puppet-stoplight

This module manages Stoplight, a powerful build monitoring tool.
Ruby
1
star
61

fx-attribution-data-reader

Attribution data reader for Firefox installers
JavaScript
1
star
62

drnd.me

CSS
1
star
63

universal-express-http-context

DEPRECATED: the work highlighted here has been merged into upstream.
JavaScript
1
star