1
0
mirror of synced 2025-03-14 00:26:08 +03:00

add createConnection static method

This commit is contained in:
Peter Gribanov 2016-06-08 10:58:44 +03:00
parent 741da7806c
commit fadd0a338f

View File

@ -836,19 +836,38 @@ use Doctrine\Common\Util\ClassUtils;
throw ORMException::missingMappingDriverImpl();
}
$conn = static::createConnection($conn, $config, $eventManager);
return new EntityManager($conn, $config, $conn->getEventManager());
}
/**
* Factory method to create Connection instances.
*
* @param mixed $conn An array with the connection parameters or an existing Connection instance.
* @param Configuration $config The Configuration instance to use.
* @param EventManager $eventManager The EventManager instance to use.
*
* @return Connection
*
* @throws ORMException
* @throws \Doctrine\DBAL\DBALException
*/
protected static function createConnection($conn, Configuration $config, EventManager $eventManager = null)
{
if (is_array($conn)) {
$conn = DriverManager::getConnection(
$conn, $config, ($eventManager ?: new EventManager())
);
} elseif ($conn instanceof Connection) {
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
throw ORMException::mismatchedEventManager();
}
} else {
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
return new EntityManager($conn, $config, $conn->getEventManager());
return $conn;
}
/**