Skip to content

Commit

Permalink
Refactor ProxyFactory
Browse files Browse the repository at this point in the history
Renamed from ReferenceProxyFactory to ProxyFactory
Moved instantiation of factory to DocumentManager
  • Loading branch information
uwej711 committed Oct 22, 2011
1 parent 49d8cd2 commit 6a41185
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
25 changes: 24 additions & 1 deletion lib/Doctrine/ODM/PHPCR/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Configuration
'validateDoctrineMetadata' => true,
'metadataDriverImpl' => null,
'documentNameMapper' => null,
'proxyNamespace' => 'MyPHPCRProxyNS'
'proxyNamespace' => 'MyPHPCRProxyNS',
'autoGenerateProxyClasses' => true
);

/**
Expand Down Expand Up @@ -210,4 +211,26 @@ public function getProxyNamespace()
{
return $this->attributes['proxyNamespace'];
}

/**
* Sets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @param boolean $bool
*/
public function setAutoGenerateProxyClasses($bool)
{
$this->attributes['autoGenerateProxyClasses'] = $bool;
}

/**
* Gets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @return boolean
*/
public function getAutoGenerateProxyClasses()
{
return $this->attributes['autoGenerateProxyClasses'];
}
}
21 changes: 21 additions & 0 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\ODM\PHPCR;

use Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory;
use Doctrine\ODM\PHPCR\Proxy\ProxyFactory;
use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -55,6 +56,11 @@ class DocumentManager implements ObjectManager
*/
private $unitOfWork = null;

/**
* @var ProxyFactory
*/
private $proxyFactory = null;

/**
* @var array
*/
Expand All @@ -79,6 +85,21 @@ public function __construct(SessionInterface $session, Configuration $config = n
$this->evm = $evm ?: new EventManager();
$this->metadataFactory = new ClassMetadataFactory($this);
$this->unitOfWork = new UnitOfWork($this, $this->config->getDocumentNameMapper());
$this->proxyFactory = new ProxyFactory($this,
$this->config->getProxyDir(),
$this->config->getProxyNamespace(),
$this->config->getAutoGenerateProxyClasses()
);
}

/**
* Gets the proxy factory used by the DocumentManager to create document proxies.
*
* @return ProxyFactory
*/
public function getProxyFactory()
{
return $this->proxyFactory;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* This whole thing is copy & pasted from ORM - should really be slightly
* refactored to generate
*/
class ReferenceProxyFactory
class ProxyFactory
{
/** The DocumentManager this factory is bound to. */
private $dm;
Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs;
use Doctrine\ODM\PHPCR\Event\OnFlushEventArgs;
use Doctrine\ODM\PHPCR\Event\OnClearEventArgs;
use Doctrine\ODM\PHPCR\Proxy\ReferenceProxyFactory;

use PHPCR\PropertyType;

Expand Down Expand Up @@ -278,10 +277,9 @@ public function createDocument($documentName, $node, array &$hints = array())
$documentState[$class->associationsMappings[$assocName]['fieldName']] = $this->identityMap[$referencedId];
} else {
$config = $this->dm->getConfiguration();
$this->referenceProxyFactory = new ReferenceProxyFactory($this->dm, $config->getProxyDir(), $config->getProxyNamespace(), true);

$referencedClass = $this->dm->getMetadataFactory()->getMetadataFor(ltrim($assocOptions['targetDocument'], '\\'));
$proxyDocument = $this->referenceProxyFactory->getProxy($referencedClass->name, $referencedId);
$proxyDocument = $this->dm->getProxyFactory()->getProxy($referencedClass->name, $referencedId);

// register the referenced document under its own id
$this->registerManaged($proxyDocument, $referencedId, null);
Expand All @@ -304,7 +302,6 @@ public function createDocument($documentName, $node, array &$hints = array())
}

$config = $this->dm->getConfiguration();
$this->referenceProxyFactory = new Proxy\ReferenceProxyFactory($this->dm, $config->getProxyDir(), $config->getProxyNamespace(), true);

foreach ($proxyNodes as $referencedNode) {
$referencedId = $referencedNode->getPath();
Expand All @@ -313,7 +310,7 @@ public function createDocument($documentName, $node, array &$hints = array())
$documentState[$class->associationsMappings[$assocName]['fieldName']][] = $this->identityMap[$referencedId];
} else {
$referencedClass = $this->dm->getMetadataFactory()->getMetadataFor(ltrim($assocOptions['targetDocument'], '\\'));
$proxyDocument = $this->referenceProxyFactory->getProxy($referencedClass->name, $referencedId);
$proxyDocument = $this->dm->getProxyFactory()->getProxy($referencedClass->name, $referencedId);

// register the referenced document under its own id
$this->registerManaged($proxyDocument, $referencedId, null);
Expand Down

0 comments on commit 6a41185

Please sign in to comment.