Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
Last active April 13, 2022 10:51
Show Gist options
  • Save reanim8ed/d94572d26f6513688a112ef7010284f0 to your computer and use it in GitHub Desktop.
Save reanim8ed/d94572d26f6513688a112ef7010284f0 to your computer and use it in GitHub Desktop.
[Controller versioning] #symfony

With FOS rest installed:

fos_rest.yaml:

versioning:
    enabled: true
    resolvers:
        query: true # Query parameter: /users?version=v1
        custom_header: true # X-Accept-Version header
    guessing_order:
        - custom_header
        - query

Request:

X-Accept-Version: 10

In DOCBLOCK:

condition="request.attributes.get('version') == '10'

In controller:

$request->attributes->get('version')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment