Skip to content

Commit

Permalink
Merge pull request #3 from kuborgh/FEAT-symfonydatabase
Browse files Browse the repository at this point in the history
allow default symfony database configuration
  • Loading branch information
hgiesenow committed Sep 4, 2014
2 parents 6c512e0 + a0eab58 commit b6204cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Traits/DatabaseConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,52 @@
use Doctrine\DBAL\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Database connection trait.
* Provides helper functions to get the database connection on the current system.
*/
trait DatabaseConnectionTrait
{
/**
* Get database connection.
*
* @throws \Exception
*
* @return string[]
*/
protected function getDatabaseParameter()
{
if($this->getContainer()->getParameter('data_transfer_bundle.siteaccess')) {
return $this->getEzPublishDatabase();
} else {
return $this->getSymfonyDatabase();
}
}

/**
* Use default parameters ( should be provided in parameters.yml )
*
* @return string[]
*/
private function getSymfonyDatabase()
{
return array(
'dbName' => $this->getContainer()->getParameter('database_name'),
'dbUser' => $this->getContainer()->getParameter('database_user'),
'dbPass' => $this->getContainer()->getParameter('database_password'),
'dbHost' => $this->getContainer()->getParameter('database_host')
);
}

/**
* Get database from eZ publish.
* Works with new doctrine connection and legacy configuration.
*
* @throws \Exception
*
* @return string[]
*/
private function getEzPublishDatabase()
{
// Fetch db connection data
$siteaccess = $this->getContainer()->getParameter('data_transfer_bundle.siteaccess');
Expand Down

0 comments on commit b6204cd

Please sign in to comment.