DoctrineInitializer.php 933 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Bridge\Doctrine\Validator;
  11. use Doctrine\Common\Persistence\ManagerRegistry;
  12. use Symfony\Component\Validator\ObjectInitializerInterface;
  13. /**
  14. * Automatically loads proxy object before validation.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class DoctrineInitializer implements ObjectInitializerInterface
  19. {
  20. protected $registry;
  21. public function __construct(ManagerRegistry $registry)
  22. {
  23. $this->registry = $registry;
  24. }
  25. public function initialize($object)
  26. {
  27. $manager = $this->registry->getManagerForClass(\get_class($object));
  28. if (null !== $manager) {
  29. $manager->initializeObject($object);
  30. }
  31. }
  32. }