Download the PHP package lcobucci/content-negotiation-middleware without Composer

On this page you can find all versions of the php package lcobucci/content-negotiation-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package content-negotiation-middleware

Content negotiation middleware

Total Downloads Latest Stable Version Unstable Version

Build Status Code Coverage

Motivation

Packages like middlewares/negotiation do a very good job to detect the correct content type based on the Accept header (or extension in the URI), however they delegate to the RequestHandler to format the content according to the detected mime type.

That works fine for most cases but it usually creates a lot of duplication in complex software, where every single RequestHandler should do that formatting (or depend on some component to do that). That logic should also be added to the middleware that handles exceptions and converts them to the appropriated HTTP response.

The goal of this middleware is to provide full content negotiation (detection and formatting).

Installation

This package is available on Packagist, and we recommend you to install it using Composer:

Adventure mode

If you're ready for an adventure and don't want to use middlewares/negotiation to handle the detection or laminas/diactoros to create the response body (StreamInterface implementation), don't despair! You'll only have to use the normal ContentTypeMiddleware::__construct() instead of ContentTypeMiddleware::fromRecommendedSettings().

We do have a small preference for the mentioned packages and didn't want to reinvent the wheel... but you know, it's a free world.

PHP Configuration

In order to make sure that other components are returning the expected objects we decided to use assert(), which is a very interesting feature in PHP but not often used. The nice thing about assert() is that we can (and should) disable it in production mode so that we don't have useless statements.

So, for production mode, we recommend you to set zend.assertions to -1 in your php.ini. For development, you should leave zend.assertions as 1 and set assert.exception to 1, which will make PHP throw an AssertionError when things go wrong.

Check the documentation for more information: https://secure.php.net/manual/en/function.assert.php

Usage

Your very first step is to create the middleware using the correct configuration:

Then you must add the middleware to very beginning of your pipeline, which will depend on the library/framework you're using, but it will be something similar to this:

Finally, you just need to use UnformattedResponse as return of the request handlers you create to trigger to formatting when needed:

Formatters

We provide some basic formatters by default:

If you want to create a customised formatter the only thing needed is to implement the Formatter interface:

License

MIT, see LICENSE.


All versions of content-negotiation-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.0 || ~8.3.0
ext-json Version *
fig/http-message-util Version ^1.1.5
psr/http-factory Version ^1.0.2
psr/http-message Version ^1.1 || ^2.0
psr/http-server-middleware Version ^1.0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lcobucci/content-negotiation-middleware contains the following files

Loading the files please wait ....