peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.33k stars 202 forks source link

Expose ability to override PDO drivers from user code #1057

Closed Alikont closed 2 years ago

Alikont commented 2 years ago

PDOEngine has private and internal mechanism to resolve drivers based on loaded assemblies, but assemblies and classes are hardcoded to predefined list of drivers.

I'd like to have an ability to add custom drivers to this list, or override existing drivers there to provide my own implementation.

Currently as a workaround we use this code on app startup:

var s_lazydrivers = typeof(PDOEngine).GetField("s_lazydrivers", BindingFlags.NonPublic | BindingFlags.Static);
var driver = new CustomPDOSqlServerDriver();
var drivers = new Dictionary<string, PDODriver>()
{
    [driver.Name] = driver,
};
s_lazydrivers.SetValue(null, drivers);

Ideally I'd like to have something like void PDOEngine.RegisterDriver(PDODriver driver)

jakubmisek commented 2 years ago

thanks for the issue; you're right, it used to register the drivers dynamically, but for some reason, we hardcoded the list of drivers (probably because nobody was implementing their custom driver before).

We should implement the driver registration again.