canonicalizer.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. FOSUserBundle Canonicalization
  2. ==============================
  3. FOSUserBundle stores canonicalized versions of the username and the email
  4. which are used when querying and checking for uniqueness.
  5. The default implementation simply makes them case-insensitive to avoid having
  6. users whose username only differs because of the case. It uses :phpfunction:`mb_convert_case`
  7. to achieve this result.
  8. .. caution::
  9. If you do not have the mbstring extension installed you will need to
  10. define your own canonicalizer.
  11. Replacing the canonicalizers
  12. ----------------------------
  13. If you want to change the way the canonical fields are populated, simply
  14. create a class implementing ``FOS\UserBundle\Util\CanonicalizerInterface``
  15. and register it as a service:
  16. .. code-block:: yaml
  17. # app/config/services.yml
  18. services:
  19. app.my_canonicalizer:
  20. class: AppBundle\Util\CustomCanonicalizer
  21. public: false
  22. You can now configure FOSUserBundle to use your own implementation:
  23. .. code-block:: yaml
  24. # app/config/config.yml
  25. fos_user:
  26. # ...
  27. service:
  28. email_canonicalizer: app.my_canonicalizer
  29. username_canonicalizer: app.my_canonicalizer
  30. You can of course use different services for each field if you don't want
  31. to use the same logic.
  32. .. note::
  33. The default implementation has the id ``fos_user.util.canonicalizer.default``.