Symfony 2 - FOSRestBundle - CSV序列化程序的格式侦听器

Im trying to see if a url has .csv on the end and if it does I need to set the format to CSV.

So i have tried to set up a format listener and this is what i have done so far

I have added this to the config file framework section:

request:
    formats:
        csv: 'text/csv'

Then I have this in the fos_rest section

fos_rest:
routing_loader:
    default_format: json
view:
    view_response_listener: true
    mime_types: { 'csv': ['text/csv','text/plain'] }
    formats:
        csv: true
        json: true
serializer:
    groups: [ Default ]
    serialize_null: true
service:
    view_handler: my.rest.view.handler
exception:
    codes:
        'test\testBundle\Exception\InvalidPageException': 404
format_listener:
    enabled: true
    rules:
        - { path: '^/api', priorities: ['csv', 'json'], fallback_format: json, exception_fallback_format: json , prefer_extension: false }

now this kind of works as it does set the format to csv, my problem is that it sets the format to csv for every request and not just when the url has .csv at the end

can anyone advise what i am doing wrong or what i am missing?