<commit_before># Negotiation Middleware

Negotiation Middleware provides content negotiation middleware for PHP applications using a middleware signature that
requires a request object, a response object, and the next callable in the middleware stack.

This library depends on willdurand/negotation for content negotiation. It allows you to add negotiation to a middleware
stack that:

1. Identifies and matches against a list of acceptable media types.
2. Supplies a default media type in the absence of an Accept request header.
3. Enriches the request object with the negotiated media type.

If the negotiator cannot determine which media type to use in response to the request, it will return a response with a
406 Not Acceptable status.

## Installation

(Notes for installing via composer to come.)

## Usage

Add an instance of NegotiationMiddleware to an application or route level middleware stack, passing two arguments to the
constructor: an array of acceptable media types to be matched against and a boolean indicating whether or not the
middleware should simply match the first acceptable media type in the absence of an Accept header in the request.

Example from Slim 3.x:

```php
<?php

use \NegotiationMiddleware\Negotiator;

$app = new \Slim\App();

$app
    ->get('/hello', function(Slim\Http\Request $request, Slim\Http\Response $response, $args) {
        return $response->write('Hello, world!');
    })
    ->add(new Negotiator(['text/html', 'application/json'], TRUE));

```

In this case, a request to /hello from a web browser will more than likely match the text/html media type specified as
an acceptable media type for this route (which is just as well, given our response isn't valid JSON). However, if the<commit_msg>Update the installation section with composer instructions.<commit_after># NegotiationMiddleware

NegotiationMiddleware provides content negotiation middleware for PHP applications using a middleware signature that
requires a request object, a response object, and the next callable in the middleware stack.

This library depends on willdurand/negotation for content negotiation. It allows you to add negotiation to a middleware
stack that:

1. Identifies and matches against a list of acceptable media types.
2. Supplies a default media type in the absence of an Accept request header.
3. Enriches the request object with the negotiated media type.

If the negotiator cannot determine which media type to use in response to the request, it will return a response with a
406 Not Acceptable status.

## Installation

Use [Composer](https://getcomposer.org/) to install NegotiationMiddleware:

```bash
$ composer require rszrama/negotiation-middleware
```

This will install the library and its dependencies. NegotiationMiddleware requires PHP 5.4.0 or newer.

## Usage

Add an instance of NegotiationMiddleware\Negotiator to an application or route level middleware stack, passing two
arguments to the constructor: an array of acceptable media types to be matched against and a boolean indicating
whether or not the middleware should simply match the first acceptable media type in the absence of an Accept header
in the request.

Example from Slim 3.x:

```php
<?php

use \NegotiationMiddleware\Negotiator;

$app = new \Slim\App();

$app
    ->get('/hello', function(Slim\Http\Request $request, Slim\Http\Response $response, $args) {
        return $response->write('Hello, world!');
    })
    ->add(new Negotiator(['text/html', 'application/json'], TRUE));

```

In this case, a request to /hello from a web browser will more than likely match the text/html media type specified as
an acceptable media type for this route (which is just as well, given our response isn't valid JSON). However, if the
{'fraction_non_alphanumeric': 0.0624, 'fraction_numerical': 0.004533333333333334, 'mean_word_length': 4.632132132132132, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1807844', 'n_tokens_mistral': 966, 'n_tokens_neox': 930, 'n_words': 511}