lib/Doctrine/ORM/EntityManager.php
protected static function createConnection($connection, Configuration $config, ?EventManager $eventManager = null)
    {
        if (is_array($connection)) {
            return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
        }

        if (! $connection instanceof Connection) {
            throw new InvalidArgumentException(
                sprintf(
                    'Invalid $connection argument of type %s given%s.',
                    is_object($connection) ? get_class($connection) : gettype($connection),
                    is_object($connection) ? '' : ': "' . $connection . '"'
                )
            );
        }

        if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
            throw MismatchedEventManager::create();
        }

        return $connection;
    }
protected static function createConnection($connection, Configuration $config, ?EventManager $eventManager = null)
    {
        if (is_array($connection)) {
            return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager());
        }

        if (! $connection instanceof Connection) {
            throw new InvalidArgumentException(
                sprintf(
                    'Invalid $connection argument of type %s given%s.',
                    is_object($connection) ? get_class($connection) : gettype($connection),
                    is_object($connection) ? '' : ': "' . $connection . '"'
                )
            );
        }

        if ($eventManager !== null && $connection->getEventManager() !== $eventManager) {
            throw MismatchedEventManager::create();
        }

        return $connection;
    }
protected static function createConnection ( $ connection , Configuration $ config , ? EventManager $ eventManager = null ) { if ( is_array ( $ connection ) ) { return DriverManager :: getConnection ( $ connection , $ config , $ eventManager ? : new EventManager ( ) ) ; } if ( ! $ connection instanceof Connection ) { throw new InvalidArgumentException ( sprintf ( 'Invalid $connection argument of type %s given%s.' , is_object ( $ connection ) ? get_class ( $ connection ) : gettype ( $ connection ) , is_object ( $ connection ) ? '' : ': "' . $ connection . '"' ) ) ; } if ( $ eventManager !== null && $ connection -> getEventManager ( ) !== $ eventManager ) { throw MismatchedEventManager :: create ( ) ; } return $ connection ; }
Factory method to create Connection instances.

@param Connection|mixed[] $connection   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 InvalidArgumentException
@throws ORMException
Factory method to create Connection instances .