I'll be submitting some pull requests I've been working on this weekend and wanted to also get some feedback here.
Currently, I find it a real pain to try to add "adapters" [and some related types] because their directory related.
IE from adapter.php:
/**
* Loads all adapters.
*
* @param array $options Adapter options
*
* @return void
*
* @since 11.1
*/
public function loadAllAdapters($options = array())
{
$list = JFolder::files($this->_basepath . '/' . $this->_adapterfolder);
foreach ($list as $filename)
{
if (JFile::getExt($filename) == 'php')
{
// Try to load the adapter object
require_once $this->_basepath . '/' . $this->_adapterfolder . '/' . $filename;
$name = JFile::stripExt($filename);
$class = $this->_classprefix . ucfirst($name);
if (!class_exists($class))
{
// Skip to next one
continue;
}
$adapter = new $class($this, $this->_db, $options);
$this->_adapters[$name] = clone $adapter;
}
}
}
}
Adapters must be in the specific folder in order to be used. To get around that, you have to use a system plugin to call setAdapter before the adapter is to be used.
Instead, I would like to use:
JPluginHelper::importPlugin('adapters');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onAdapterLoadAdapters', $this, $options);
This would allow a plugin written to run onAdapterLoad to check the adapter class being loaded, and if it matches call setAdapter to load additional adapters.
For example, if you need an "application" package class for the installer, you could program:
function onAdapterLoadAdapters($adapter, $options)
{
if (is_a($adapter,'JInstaller', false) {
if !(class_exists('JInstallerApplication') {
// Try to load the adapter object
include_once $this->_basepath . '/path/to/my/adapter/application.php';
if (class_exists('JInstallerApplication') {
$adapter = new JInstallerApplication($adapter, $adapter->_db, $options);
$adapter->setAdapter($adapter);
}
}
}
}
By the same token, I'm adding the same functionality to:
JSession for session stores.
JDatabaseFactory for database drivers
JCache for cache stores
JCacheController for cache controllers
I wanted to see if anyone has a better suggestion for setting these up so that additional adapters/storage mechanisms can be added without having to place them in the core directories.
Note JDatabaseFactory is a bit of an oddball since the plugin system depends on the database to function..so while it would be possible to use it to load /additional/ database drivers, it can't be used to load the default database driver.. the easy way around that would be to use the old directory based plugin system for JDatabaseFactory...the cleaner way to handle it would be to specifically add the path of the default database driver to JConfig and load it so it is always available.