I've just made some significant changes to the way ILS drivers work in VuFind 2.0. There are now two more mandatory methods on the driver interface:
setConfig($config) - set a config array
init() - validate configuration and initialize resources
The reason for this change is to prepare drivers for the plugin manager and to make them more flexible.
In the old system, drivers loaded their own configurations automatically using the VuFind\Config\Reader. Additionally, many drivers did heavy-weight tasks in their constructors such as establishing database connections.
In the new system, configuration loading is handled by the VuFind\ILS\Connection class. It automatically finds the configuration file that corresponds with the driver class name, injects it via setConfig(), and then calls init() to finish configuring the object.
This has a few advantages:
- Extremely redundant config loading logic has been removed from all of the driver constructors
- Drivers are now more flexible -- they are easier to reuse outside of VuFind's normal context, since you can inject configurations however you like
- Lightweight constructors make lazy-loading easier; we can build an object inexpensively and only call init() when we are ready to use it
There's one obvious disadvantage: constructing a driver is now more complex (three steps rather than one) and if you do things in the wrong order, you can cause an error. However, I think this is a small price to pay, since driver initialization is handled centrally, so this complexity won't affect most people. Driver authors just need to follow the interface, and it doesn't really matter to them what is happening on the outside.
I still need to do a bit more refactoring before I actually have drivers loading from a plugin manager... but I think the driver interface itself shouldn't change much beyond this point. Comments and questions are welcome!