Initializer.php 952 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\UserBundle\Validator;
  11. use FOS\UserBundle\Model\UserInterface;
  12. use FOS\UserBundle\Model\UserManagerInterface;
  13. use Symfony\Component\Validator\ObjectInitializerInterface;
  14. /**
  15. * Automatically updates the canonical fields before validation.
  16. *
  17. * @author Christophe Coevoet <stof@notk.org>
  18. */
  19. class Initializer implements ObjectInitializerInterface
  20. {
  21. private $userManager;
  22. public function __construct(UserManagerInterface $userManager)
  23. {
  24. $this->userManager = $userManager;
  25. }
  26. public function initialize($object)
  27. {
  28. if ($object instanceof UserInterface) {
  29. $this->userManager->updateCanonicalFields($object);
  30. }
  31. }
  32. }