public static create ( mixed $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager = null ) : |
||
$conn | mixed | An array with the connection parameters or an existing Connection instance. |
$config | Doctrine\ORM\Configuration | The Configuration instance to use. |
$eventManager | Doctrine\Common\EventManager | The EventManager instance to use. |
return | The created EntityManager. |
public static function create($conn, Configuration $config, EventManager $eventManager = null)
{
if (!$config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
if (is_array($conn)) {
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager()));
} else if ($conn instanceof Connection) {
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
} else {
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
return new EntityManager($conn, $config, $conn->getEventManager());
}
/** * Because the EntityManager gets closed when there's an error, it needs to * be created again * * @return EntityManager * @throws ORMException */ protected function getEntityManager() { if (!$this->em) { $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); } if (!$this->em->isOpen()) { $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration()); } return $this->em; }