[DependencyInjection] added a way to change the DBAL driver in the Doctrine extension
This commit is contained in:
parent
9b3eec8861
commit
b58c685508
@ -49,7 +49,7 @@ class DoctrineExtension extends LoaderExtension
|
||||
$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]))
|
||||
{
|
||||
@ -57,6 +57,17 @@ class DoctrineExtension extends LoaderExtension
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user