silverstripe-framework/dev/install/DatabaseAdapterRegistry.php
Sean Harvey 9367dc40a1 MINOR Fixed PHP strict standard where non-variables cannot be passed by reference
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@113968 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:20:01 +13:00

81 lines
2.3 KiB
PHP

<?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 {
static $default_fields = array(
'server' => array(
'title' => 'Database server',
'envVar' => 'SS_DATABASE_SERVER',
'default' => 'localhost'
),
'username' => array(
'title' => 'Database username',
'envVar' => 'SS_DATABASE_USERNAME',
'default' => 'root'
),
'password' => array(
'title' => 'Database password',
'envVar' => 'SS_DATABASE_PASSWORD',
'default' => 'password'
),
'database' => array(
'title' => 'Database name',
'default' => 'SS_mysite',
'attributes' => array(
"onchange" => "this.value = this.value.replace(/[\/\\:*?&quot;<>|. \t]+/g,'');"
)
),
);
/**
* Internal array of registered database adapters
*/
private static $adapters = array();
/**
* Add new adapter to the registry
* @param array $config Associative array of configuration details
*/
static function register($config) {
$missingExtensionText = isset($config['missingExtensionText'])
? $config['missingExtensionText']
: 'The PHP extension is missing, please enable or install it.';
$path = explode('/', $config['helperPath']);
$moduleName = array_shift($path);
$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;
// set default fields if none are defined already
if(!isset($config['fields'])) $config['fields'] = self::$default_fields;
self::$adapters[$config['class']] = $config;
}
static function unregister($class) {
if(isset($adapters[$class])) unset($adapters[$class]);
}
static function autodiscover() {
foreach(glob(dirname(__FILE__) . '/../../../*', GLOB_ONLYDIR) as $directory) {
if(file_exists($directory . '/_register_database.php')) include_once($directory . '/_register_database.php');
}
}
static function get_adapters() {
return self::$adapters;
}
}