{"id":15031227,"url":"https://github.com/willdurand/negotiation","last_synced_at":"2025-05-14T02:05:12.242Z","repository":{"id":6453223,"uuid":"7692851","full_name":"willdurand/Negotiation","owner":"willdurand","description":"Content Negotiation tools for PHP.","archived":false,"fork":false,"pushed_at":"2023-08-03T17:52:44.000Z","size":348,"stargazers_count":1419,"open_issues_count":9,"forks_count":63,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-05-13T23:56:40.444Z","etag":null,"topics":["content-negotiation","negotiation","php"],"latest_commit_sha":null,"homepage":"https://williamdurand.fr/Negotiation/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willdurand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-01-18T19:28:50.000Z","updated_at":"2025-05-12T07:54:01.000Z","dependencies_parsed_at":"2023-02-17T21:00:58.464Z","dependency_job_id":"245f02b8-e577-44c7-8395-43ab21b847dc","html_url":"https://github.com/willdurand/Negotiation","commit_stats":{"total_commits":177,"total_committers":33,"mean_commits":5.363636363636363,"dds":0.6779661016949152,"last_synced_commit":"68e9ea0553ef6e2ee8db5c1d98829f111e623ec2"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willdurand%2FNegotiation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willdurand%2FNegotiation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willdurand%2FNegotiation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willdurand%2FNegotiation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willdurand","download_url":"https://codeload.github.com/willdurand/Negotiation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052692,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["content-negotiation","negotiation","php"],"created_at":"2024-09-24T20:15:12.239Z","updated_at":"2025-05-14T02:05:07.081Z","avatar_url":"https://github.com/willdurand.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Negotiation\n===========\n\n[![GitHub Actions](https://github.com/willdurand/Negotiation/workflows/ci/badge.svg)](https://github.com/willdurand/Negotiation/actions?query=workflow%3A%22ci%22+branch%3Amaster)\n[![Total\nDownloads](https://poser.pugx.org/willdurand/Negotiation/downloads.png)](https://packagist.org/packages/willdurand/Negotiation)\n[![Latest Stable\nVersion](https://poser.pugx.org/willdurand/Negotiation/v/stable.png)](https://packagist.org/packages/willdurand/Negotiation)\n\n**Negotiation** is a standalone library without any dependencies that allows you\nto implement [content\nnegotiation](https://tools.ietf.org/html/rfc7231#section-5.3) in your\napplication, whatever framework you use.  This library is based on [RFC\n7231](https://tools.ietf.org/html/rfc7231). Negotiation is easy to use, and\nextensively unit tested!\n\n\u003e **Important:** You are browsing the documentation of Negotiation **3.x**+.\n\u003e\n\u003e Documentation for version **1.x** is available here: [Negotiation 1.x\n\u003e documentation](https://github.com/willdurand/Negotiation/blob/1.x/README.md#usage).\n\u003e\n\u003e Documentation for version **2.x** is available here: [Negotiation 2.x\n\u003e documentation](https://github.com/willdurand/Negotiation/blob/2.x/README.md#usage).\n\n\nInstallation\n------------\n\nThe recommended way to install Negotiation is through\n[Composer](http://getcomposer.org/):\n\n```bash\n$ composer require willdurand/negotiation\n```\n\n\nUsage Examples\n--------------\n\n### Media Type Negotiation\n\n``` php\n$negotiator = new \\Negotiation\\Negotiator();\n\n$acceptHeader = 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';\n$priorities   = array('text/html; charset=UTF-8', 'application/json', 'application/xml;q=0.5');\n\n$mediaType = $negotiator-\u003egetBest($acceptHeader, $priorities);\n\n$value = $mediaType-\u003egetValue();\n// $value == 'text/html; charset=UTF-8'\n```\n\nThe `Negotiator` returns an instance of `Accept`, or `null` if negotiating the\nbest media type has failed.\n\n### Language Negotiation\n\n``` php\n\u003c?php\n\n$negotiator = new \\Negotiation\\LanguageNegotiator();\n\n$acceptLanguageHeader = 'en; q=0.1, fr; q=0.4, fu; q=0.9, de; q=0.2';\n$priorities          = array('de', 'fu', 'en');\n\n$bestLanguage = $negotiator-\u003egetBest($acceptLanguageHeader, $priorities);\n\n$type = $bestLanguage-\u003egetType();\n// $type == 'fu';\n\n$quality = $bestLanguage-\u003egetQuality();\n// $quality == 0.9\n```\n\nThe `LanguageNegotiator` returns an instance of `AcceptLanguage`.\n\n### Encoding Negotiation\n\n``` php\n\u003c?php\n\n$negotiator = new \\Negotiation\\EncodingNegotiator();\n$encoding   = $negotiator-\u003egetBest($acceptHeader, $priorities);\n```\n\nThe `EncodingNegotiator` returns an instance of `AcceptEncoding`.\n\n### Charset Negotiation\n\n``` php\n\u003c?php\n\n$negotiator = new \\Negotiation\\CharsetNegotiator();\n\n$acceptCharsetHeader = 'ISO-8859-1, UTF-8; q=0.9';\n$priorities          = array('iso-8859-1;q=0.3', 'utf-8;q=0.9', 'utf-16;q=1.0');\n\n$bestCharset = $negotiator-\u003egetBest($acceptCharsetHeader, $priorities);\n\n$type = $bestCharset-\u003egetType();\n// $type == 'utf-8';\n\n$quality = $bestCharset-\u003egetQuality();\n// $quality == 0.81\n```\n\nThe `CharsetNegotiator` returns an instance of `AcceptCharset`.\n\n### `Accept*` Classes\n\n`Accept` and `Accept*` classes share common methods such as:\n\n* `getValue()` returns the accept value (e.g. `text/html; z=y; a=b; c=d`)\n* `getNormalizedValue()` returns the value with parameters sorted (e.g.\n  `text/html; a=b; c=d; z=y`)\n* `getQuality()` returns the quality if available (`q` parameter)\n* `getType()` returns the accept type (e.g. `text/html`)\n* `getParameters()` returns the set of parameters (excluding the `q` parameter\n  if provided)\n* `getParameter()` allows to retrieve a given parameter by its name. Fallback to\n  a `$default` (nullable) value otherwise.\n* `hasParameter()` indicates whether a parameter exists.\n\n\nVersioning\n----------\n\nNegotiation follows [Semantic Versioning](http://semver.org/).\n\n### End Of Life\n\n#### 1.x\n\nAs of October 2016, [branch\n`1.x`](https://github.com/willdurand/Negotiation/tree/1.x) is not supported\nanymore, meaning major version `1` reached end of life. Last version is:\n[1.5.0](https://github.com/willdurand/Negotiation/releases/tag/1.5.0).\n\n#### 2.x\n\nAs of November 2020, [branch\n`2.x`](https://github.com/willdurand/Negotiation/tree/2.x) is not supported\nanymore, meaning major version `2` reached end of life. Last version is:\n[2.3.1](https://github.com/willdurand/Negotiation/releases/tag/v2.3.1).\n\n### Stable Version\n\n#### 3.x (and `dev-master`)\n\nNegotiation [3.0](https://github.com/willdurand/Negotiation/releases/tag/3.0.0)\nhas been released on November 26th, 2020. This is the **current stable version**\nand it is in sync with the main branch (a.k.a. `master`).\n\nUnit Tests\n----------\n\nSetup the test suite using Composer:\n\n    $ composer install --dev\n\nRun it using PHPUnit:\n\n    $ phpunit\n\n\nContributing\n------------\n\nSee [CONTRIBUTING](CONTRIBUTING.md) file.\n\n\nCredits\n-------\n\n* Some parts of this library are inspired by:\n\n    * [Symfony](http://github.com/symfony/symfony) framework;\n    * [FOSRest](http://github.com/FriendsOfSymfony/FOSRest);\n    * [PEAR HTTP2](https://github.com/pear/HTTP2).\n\n* [William Durand](https://github.com/willdurand)\n* [@neural-wetware](https://github.com/neural-wetware)\n\n\nLicense\n-------\n\nNegotiation is released under the MIT License. See the bundled LICENSE file for\ndetails.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilldurand%2Fnegotiation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilldurand%2Fnegotiation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilldurand%2Fnegotiation/lists"}