eZ\Bundle\EzPublishLegacySearchEngineBundle\ApiLoader\ConnectionFactory::getConnection PHP Method

getConnection() public method

Returns database connection used by database handler.
public getConnection ( ) : Doctrine\DBAL\Connection
return Doctrine\DBAL\Connection
    public function getConnection()
    {
        $repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();
        // Taking provided connection name if any.
        // Otherwise, just fallback to the default connection.
        if (isset($repositoryConfig['search']['connection'])) {
            $doctrineConnectionId = sprintf('doctrine.dbal.%s_connection', $repositoryConfig['search']['connection']);
        } else {
            // "database_connection" is an alias to the default connection, set up by DoctrineBundle.
            $doctrineConnectionId = 'database_connection';
        }
        if (!$this->container->has($doctrineConnectionId)) {
            throw new InvalidArgumentException("Invalid Doctrine connection '{$repositoryConfig['search']['connection']}' for repository '{$repositoryConfig['alias']}'." . 'Valid connections are ' . implode(', ', array_keys($this->container->getParameter('doctrine.connections'))));
        }
        return $this->container->get($doctrineConnectionId);
    }