. */ namespace Doctrine\ORM\Proxy; use Doctrine\ORM\EntityManager; /** * This Factory is used to create proxy objects for entities at runtime. * * @author Roman Borschel * @author Giorgio Sironi * @since 2.0 */ class ProxyFactory { private $_em; private $_generator; /** * Initializes a new instance of the DynamicProxyGenerator class that is * connected to the given EntityManager and stores proxy class files in * the given cache directory. * * @param EntityManager $em * @param Generator $generator */ public function __construct(EntityManager $em, ProxyClassGenerator $generator) { $this->_em = $em; $this->_generator = $generator; } /** * Gets a reference proxy instance. * * @param string $className * @param mixed $identifier * @return object */ public function getReferenceProxy($className, $identifier) { $proxyClassName = $this->_generator->generateReferenceProxyClass($className); $entityPersister = $this->_em->getUnitOfWork()->getEntityPersister($className); return new $proxyClassName($entityPersister, $identifier); } /** * Gets an association proxy instance. */ public function getAssociationProxy($owner, \Doctrine\ORM\Mapping\AssociationMapping $assoc, array $joinColumnValues) { $proxyClassName = $this->_generator->generateAssociationProxyClass($assoc->getTargetEntityName()); return new $proxyClassName($this->_em, $assoc, $owner, $joinColumnValues); } }