Doctrine\ODM\CouchDB\Proxy\ProxyFactory::getProxy PHP Method

getProxy() public method

Gets a reference proxy instance for the entity of the given type and identified by the given identifier.
public getProxy ( string $className, mixed $identifier ) : object
$className string
$identifier mixed
return object
    public function getProxy($className, $identifier)
    {
        $fqn = ClassUtils::generateProxyClassName($className, $this->proxyNamespace);
        if (!class_exists($fqn, false)) {
            $fileName = $this->getProxyFileName($className);
            if ($this->autoGenerate) {
                $this->generateProxyClass($this->dm->getClassMetadata($className), $fileName, self::$proxyClassTemplate);
            }
            require $fileName;
        }
        if (!$this->dm->getMetadataFactory()->hasMetadataFor($fqn)) {
            $this->dm->getMetadataFactory()->setMetadataFor($fqn, $this->dm->getClassMetadata($className));
        }
        return new $fqn($this->dm, $identifier);
    }

Usage Example

 public function testReferenceProxyDelegatesLoadingToThePersister()
 {
     $proxyClass = 'Proxies\\__CG__\\Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature';
     $modelClass = 'Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature';
     $query = array('documentName' => '\\' . $modelClass, 'id' => 'SomeUUID');
     $uowMock = $this->getMock('Doctrine\\ODM\\CouchDB\\UnitOfWork', array('refresh'), array(), '', false);
     $uowMock->expects($this->atLeastOnce())->method('refresh')->with($this->isInstanceOf($proxyClass));
     $dmMock = new DocumentManagerMock();
     $dmMock->setUnitOfWorkMock($uowMock);
     $this->proxyFactory = new ProxyFactory($dmMock, __DIR__ . '/generated', 'Proxies', true);
     $proxy = $this->proxyFactory->getProxy($modelClass, $query['id'], $query['documentName']);
     $this->assertInstanceOf('Doctrine\\ODM\\CouchDB\\Proxy\\Proxy', $proxy);
     $proxy->getDescription();
 }
All Usage Examples Of Doctrine\ODM\CouchDB\Proxy\ProxyFactory::getProxy