This package is abandoned and no longer maintained. No replacement package was suggested.

Adds content negotiation to your Symfony application

Installs: 681

Dependents: 1

Suggesters: 1

Security: 0

Stars: 0

Watchers: 4

Forks: 1


v0.1.0 2018-12-07 14:44 UTC

This package is auto-updated.

Last update: 2020-02-07 21:07:44 UTC


Build Status

This is a Symfony bundle that will add content negotiation to your application by integrating the Negotiation library.

Getting started

Using Composer you can add the bundle as a dependency:

composer require libero/content-negotation-bundle

If you're not using Symfony Flex, you'll need to enable the bundle in your application.

Path-based negotiation

You can add negotiation to paths through configuration.

For example, to add a requirement of XML or JSON and English or French to an exact path, and plain text and German elsewhere:

        - path: ^/path/to/my/page$
          priorities: xml|json
        - path: ^/
          priorities: txt
        - path: ^/path/to/my/page$
          priorities: en|fr
        - path: ^/
          priorities: de

The formats and locales items are run in order. The first to match will be used.

priorities may be empty, allowing for negotiation to be disabled at lower levels. For example, require English everywhere except under /foo:

        - path: ^/foo($|/)
        - path: ^/
          priorities: en

optional may be set to true to allow falling back to subsequent matches. For example, to require English everywhere except under /foo, where either German or English is allowed:

        - path: ^/foo($|/)
          priorities: de
          optional: true
        - path: ^/
          priorities: en

Route-level negotiation

You can add negotiation at the route level by adding requirements for _format and/or _locale.

These requirements must be a list of possibilities separated by vertical bars.

For example, to add a requirement of XML or JSON and English or French to a route:

    path: /path/to/my/page
    controller: App\Controller\PageController
        _format: xml|json
        _locale: en|fr

Route-level negotiation takes precedence over path-based.

Getting help