2010-03-09 03:39:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class keeps track of the available database adapters
|
|
|
|
* and provides a meaning of registering community built
|
|
|
|
* adapters in to the installer process.
|
|
|
|
*
|
|
|
|
* @package installer
|
|
|
|
* @author Tom Rix
|
|
|
|
*/
|
|
|
|
class DatabaseAdapterRegistry {
|
2010-03-11 06:36:33 +01:00
|
|
|
|
2010-03-09 03:39:04 +01:00
|
|
|
/**
|
|
|
|
* Internal array of registered database adapters
|
|
|
|
*/
|
|
|
|
private static $adapters = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add new adapter to the registry
|
2010-03-11 06:36:33 +01:00
|
|
|
* @param array $config Associative array of configuration details
|
2010-03-09 03:39:04 +01:00
|
|
|
*/
|
2010-03-11 06:36:33 +01:00
|
|
|
static function register($config) {
|
|
|
|
$missingExtensionText = isset($config['missingExtensionText'])
|
|
|
|
? $config['missingExtensionText']
|
|
|
|
: 'The PHP extension is missing, please enable or install it.';
|
|
|
|
|
|
|
|
$moduleName = array_shift(explode('/', $config['helperPath']));
|
|
|
|
$missingModuleText = isset($config['missingModuleText'])
|
|
|
|
? $config['missingModuleText']
|
|
|
|
: 'The SilverStripe module, '.$moduleName.', is missing or incomplete. Please <a href="http://silverstripe.org/modules">download it</a>.';
|
|
|
|
|
|
|
|
$config['missingModuleText'] = $missingModuleText;
|
|
|
|
$config['missingExtensionText'] = $missingExtensionText;
|
|
|
|
|
|
|
|
self::$adapters[$config['class']] = $config;
|
2010-03-09 03:39:04 +01:00
|
|
|
}
|
|
|
|
|
2010-03-11 09:36:38 +01:00
|
|
|
static function unregister($class) {
|
|
|
|
if(isset($adapters[$class])) unset($adapters[$class]);
|
|
|
|
}
|
|
|
|
|
2010-03-09 03:39:04 +01:00
|
|
|
static function autodiscover() {
|
2010-03-11 06:36:33 +01:00
|
|
|
foreach(glob(dirname(__FILE__) . '/../../../*', GLOB_ONLYDIR) as $directory) {
|
|
|
|
if(file_exists($directory . '/_register_database.php')) include_once($directory . '/_register_database.php');
|
2010-03-09 03:39:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 06:36:33 +01:00
|
|
|
static function get_adapters() {
|
2010-03-09 03:39:04 +01:00
|
|
|
return self::$adapters;
|
|
|
|
}
|
2010-03-11 06:36:33 +01:00
|
|
|
|
|
|
|
}
|