/**
  * Builds storage engine identified by $storageEngineIdentifier (the "alias" attribute in the service tag).
  *
  * @throws \eZ\Bundle\EzPublishCoreBundle\ApiLoader\Exception\InvalidStorageEngine
  *
  * @return \eZ\Publish\SPI\Persistence\Handler
  */
 public function buildStorageEngine()
 {
     $repositoryConfig = $this->storageRepositoryProvider->getRepositoryConfig();
     if (!(isset($repositoryConfig['engine']) && isset($this->storageEngines[$repositoryConfig['engine']]))) {
         throw new InvalidStorageEngine("Invalid storage engine '{$repositoryConfig['engine']}'. Could not find any service tagged as ezpublish.storageEngine with alias {$repositoryConfig['engine']}.");
     }
     return $this->storageEngines[$repositoryConfig['engine']];
 }
 /**
  * @expectedException \eZ\Bundle\EzPublishCoreBundle\ApiLoader\Exception\InvalidRepositoryException
  */
 public function testGetRepositoryConfigUndefinedRepository()
 {
     $configResolver = $this->getConfigResolverMock();
     $repositories = array('main' => array('engine' => 'foo'), 'another' => array('engine' => 'bar'));
     $configResolver->expects($this->once())->method('getParameter')->with('repository')->will($this->returnValue('undefined_repository'));
     $provider = new StorageRepositoryProvider($configResolver, $repositories);
     $provider->getRepositoryConfig();
 }
 /**
  * Returns database connection used by database handler
  *
  * @throws \InvalidArgumentException
  *
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection()
 {
     $repositoryConfig = $this->storageRepositoryProvider->getRepositoryConfig();
     // Taking provided connection name if any.
     // Otherwise, just fallback to the default connection.
     if (isset($repositoryConfig['connection'])) {
         $doctrineConnectionId = sprintf('doctrine.dbal.%s_connection', $repositoryConfig['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['connection']}' for repository '{$repositoryConfig['alias']}'." . "Valid connections are " . implode(', ', array_keys($this->container->getParameter('doctrine.connections'))));
     }
     return $this->container->get($doctrineConnectionId);
 }