Search code examples
phpsymfonyconfigurationcsrf

How to replace Symfony2's CsrfProvider with another service?


Symfony2's default SessionCsrfProvider can be replaced with another service that implements CsrfProviderInterface. However, the documentation does not tell where to define the replacing service id.

The default framework configuration allows only to set field_name and enabled/disabled flag. There is no similar configuration option as "storage_id" in sessions.

So, how to replace the default CSRF Provider?


Solution

  • Add this to your config.yml

    services:
        form.csrf_provider: 
            class: YourNamespace\YourProvider
            arguments: [ @session, %kernel.secret% ]