How can I add my custom driver without modifying DriverManager.php in the Doctrine2 core?
I have created a DBAL Driver for pdo_dblib
and placed it inside a Symfony2 bundle. This works fine, however I must add my driver to a list of hard-coded drivers in DriverManager.php, otherwise I get the following exception:
Exception
[Doctrine\DBAL\DBALException]
The given 'driver' pdo_dblib is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_ibm, pdo_sqlsrv
Unless I modify DriverManager.php
final class DriverManager
{
private static $_driverMap = array(
'pdo_dblib' => 'Doctrine\DBAL\Driver\PDODblib\Driver', // Added this line
);
}
Here's my config.yml:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_dblib
driver_class: PDODblibBundle\Doctrine\DBAL\Driver\PDODblib\Driver
You actually can, just leave the driver configuration option completlely out.
All you need to define is the driver_class option. The driver is only used to do an internal lookup for the default driver classes, as long as you provide the class only, it will not fail doing the lookup.
Btw: There is no way (in a complete default setup) to define this in the parameters.ini, you have to change it directly inside the config.yml
Btw: due to another defect (driver falling back to mysql in on specific area), you may not set the charset in the configuration, as it will register an MySql event handler for setting the charset than.
So my final doctrine config based on my mssql_* based implementation looks like the following and works without problems: