vendor/symfony/src/Symfony/Bridge/Doctrine/Validator/EntityInitializer.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Bridge\Doctrine\Validator;
       
    13 
       
    14 use Symfony\Bridge\Doctrine\RegistryInterface;
       
    15 use Symfony\Component\Validator\ObjectInitializerInterface;
       
    16 use Doctrine\ORM\Proxy\Proxy;
       
    17 
       
    18 /**
       
    19  * Automatically loads proxy object before validation.
       
    20  *
       
    21  * @author Fabien Potencier <fabien@symfony.com>
       
    22  */
       
    23 class EntityInitializer implements ObjectInitializerInterface
       
    24 {
       
    25     protected $registry;
       
    26 
       
    27     public function __construct(RegistryInterface $registry)
       
    28     {
       
    29         $this->registry = $registry;
       
    30     }
       
    31 
       
    32     public function initialize($object)
       
    33     {
       
    34         if ($object instanceof Proxy) {
       
    35             $this->registry->getEntityManagerForClass(get_class($object))->getUnitOfWork()->initializeObject($object);
       
    36         }
       
    37     }
       
    38 }