1
0
mirror of synced 2025-02-21 14:43:14 +03:00

Merge pull request #150 from stof/initialize_object

Added the initializeObject method in the EntityManager
This commit is contained in:
Benjamin Eberlei 2011-10-16 08:04:46 -07:00
commit ba5e73213b

View File

@ -128,7 +128,7 @@ class EntityManager implements ObjectManager
$this->metadataFactory = new $metadataFactoryClassName; $this->metadataFactory = new $metadataFactoryClassName;
$this->metadataFactory->setEntityManager($this); $this->metadataFactory->setEntityManager($this);
$this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl());
$this->unitOfWork = new UnitOfWork($this); $this->unitOfWork = new UnitOfWork($this);
$this->proxyFactory = new ProxyFactory($this, $this->proxyFactory = new ProxyFactory($this,
$config->getProxyDir(), $config->getProxyDir(),
@ -203,18 +203,18 @@ class EntityManager implements ObjectManager
public function transactional(Closure $func) public function transactional(Closure $func)
{ {
$this->conn->beginTransaction(); $this->conn->beginTransaction();
try { try {
$return = $func($this); $return = $func($this);
$this->flush(); $this->flush();
$this->conn->commit(); $this->conn->commit();
return $return ?: true; return $return ?: true;
} catch (Exception $e) { } catch (Exception $e) {
$this->close(); $this->close();
$this->conn->rollback(); $this->conn->rollback();
throw $e; throw $e;
} }
} }
@ -244,7 +244,7 @@ class EntityManager implements ObjectManager
* *
* The class name must be the fully-qualified class name without a leading backslash * The class name must be the fully-qualified class name without a leading backslash
* (as it is returned by get_class($obj)) or an aliased class name. * (as it is returned by get_class($obj)) or an aliased class name.
* *
* Examples: * Examples:
* MyProject\Domain\User * MyProject\Domain\User
* sales:PriceRequest * sales:PriceRequest
@ -450,7 +450,7 @@ class EntityManager implements ObjectManager
* *
* The entity will be entered into the database at or before transaction * The entity will be entered into the database at or before transaction
* commit or as a result of the flush operation. * commit or as a result of the flush operation.
* *
* NOTE: The persist operation always considers entities that are not yet known to * NOTE: The persist operation always considers entities that are not yet known to
* this EntityManager as NEW. Do not pass detached entities to the persist operation. * this EntityManager as NEW. Do not pass detached entities to the persist operation.
* *
@ -633,7 +633,7 @@ class EntityManager implements ObjectManager
/** /**
* Check if the Entity manager is open or closed. * Check if the Entity manager is open or closed.
* *
* @return bool * @return bool
*/ */
public function isOpen() public function isOpen()
@ -714,6 +714,18 @@ class EntityManager implements ObjectManager
return $this->proxyFactory; return $this->proxyFactory;
} }
/**
* Helper method to initialize a lazy loading proxy or persistent collection.
*
* This method is a no-op for other objects
*
* @param object $obj
*/
public function initializeObject($obj)
{
$this->unitOfWork->initializeObject($obj);
}
/** /**
* Factory method to create EntityManager instances. * Factory method to create EntityManager instances.
* *