Skip to content

Commit

Permalink
[DependencyInjection] added a way to change the DBAL driver in the Do…
Browse files Browse the repository at this point in the history
…ctrine extension
  • Loading branch information
fabpot committed Feb 1, 2010
1 parent 9b3eec8 commit b58c685
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -49,14 +49,25 @@ public function dbalLoad($config)
$loader = new XmlFileLoader(__DIR__.'/xml/doctrine');
$configuration->merge($loader->load('dbal-1.0.xml'));

foreach (array('dbname', 'driverClass', 'host', 'username', 'password') as $key)
foreach (array('dbname', 'host', 'username', 'password') as $key)
{
if (isset($config[$key]))
{
$configuration->setParameter('doctrine.dbal.'.$key, $config[$key]);
}
}

if (isset($config['driver']))
{
$class = $config['driver'];
if (in_array($class, array('OCI8', 'PDOMsSql', 'PDOMySql', 'PDOOracle', 'PDOPgSql', 'PDOSqlite')))
{
$class = 'Doctrine\\DBAL\\Driver\\'.$class.'\\Driver';
}

$configuration->setParameter('doctrine.dbal.driver.class', $class);
}

$configuration->setAlias('connection', null !== $this->alias ? $this->alias : 'doctrine.dbal.connection');

return $configuration;
Expand Down
Expand Up @@ -12,5 +12,6 @@
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="username" type="xsd:string" />
<xsd:attribute name="password" type="xsd:string" />
<xsd:attribute name="driver" type="xsd:string" />
</xsd:complexType>
</xsd:schema>

0 comments on commit b58c685

Please sign in to comment.