Download the PHP package apitte/negotiation without Composer
On this page you can find all versions of the php package apitte/negotiation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apitte/negotiation
More information about apitte/negotiation
Files in apitte/negotiation
Package negotiation
Short Description Content-Negotiation support for Apitte stack
License MIT
Homepage https://github.com/apitte/negotiation
Informations about the package negotiation
Website 🚀 contributte.org | Contact 👨🏻💻 f3l1x.io | Twitter 🐦 @contributte
Disclaimer
| :warning: | This project is no longer being maintained. Please use contributte/apitte. |
|---|---|
| Composer | apitte/negotiation |
| Version | |
| PHP | |
| License |
Usage
To install the latest version of apitte/negotiation use Composer.
Documentation
Content negotiation for Apitte.
Transform response entity into response with unified format in dependence on Accept header and uri path suffix /api/v1/users(.json|.xml)
Setup
First of all, setup core package and enable CoreDecoratorPlugin.
Install and register negotiation plugin
Response
Instead of writing data into response body use $response->withEntity($entity) so transformers could handle transformation for you.
Entities
Value objects which are used to create response
ArrayEntity- create from arrayObjectEntity- create from stdClassScalarEntity- create from raw data
Error handling
Negotiations are implemented through an IErrorDecorator, which have higher priority than internal ErrorHandler
so response is created from exception in an ITransformer and ErrorHandler only log that exception (if you use PsrLogErrorHandler)
Negotiators
Handle request and based on path suffix or request headers call appropriate transformer.
SuffixNegotiator
- used for request with path suffix like
/api/v1/users.json-> transformer forjsonsuffix is used
DefaultNegotiator
- called when none other transform
- require annotation
@Negotiation(default = true, suffix = "json")defined on endpoint - transformer for given suffix is looked for
FallbackNegotiator
- used last if no other negotiator transformed response
- uses json transformer by default
Transformers
Transformers convert entities and exceptions into response.
JsonTransformer
- transform into json
JsonUnifyTransformer
- transform into json with unified format
CsvTransformer
- transform into csv
- known limitation: data need to be a flat structure
Implementing transformer
- register transformer for suffix
xml, used for uris like/api/v1/users.xml - if
fallback: trueis defined and none of transformers matched then use that transformer
Version
| State | Version | Branch | Nette | PHP |
|---|---|---|---|---|
| stable | ^0.8 |
master |
3.0+ | >=7.3 |
| stable | ^0.5 |
master |
2.4 | >=7.1 |
Development
This package was maintained by these authors.
Consider to support contributte development team. Also thank you for being used this package.