Download the PHP package ptlis/psr7-conneg without Composer
On this page you can find all versions of the php package ptlis/psr7-conneg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ptlis/psr7-conneg
More information about ptlis/psr7-conneg
Files in ptlis/psr7-conneg
Informations about the package psr7-conneg
PSR-7 ConNeg
A content negotiation middleware that uses the PSR-7 interfaces.
Configurable component that decorate processed requests with preferred type information.
Built upon ptlis/ConNeg.
Install
Either from the console:
Or by Editing composer.json:
Followed by a composer update:
Usage
The package ships with a single class to provide negotiation.
To opt-in to negotiation on a field use the appropriate method (note these methods return a new instance in the manner of the PSR-7 interfaces).
To negotiate the preferred mime-type use the method, providing it with a list of your application's type preference:
With your negotiator configured you can now perform negotiation:
This adds attributes to the request containing the preferred type. These can be accessed with the appropriate getters, in the above example of negotiation on the Accept field this looks like:
If the Accept field of the request contained then the value returned from this lookup would be .
With Zend-Stratigility
To use the zend-stratigility component, configure your negotiator instance as described above and pass it to the Stratigility negotiator.
To perform negotiation on all routes, add it with an empty route:
For further information please refer to the Stratigility documentation.
With Relay
To use the relay component, configure your negotiator instance as described above and pass it to the Relay negotiator.
Note: The negotiator must be earlier in the queue than middleware components that depend upon negotiation data.
Integration
Middlewares integration is shipped for the following packages:
Contributing
You can contribute by submitting an Issue to the issue tracker or submitting a pull request.