public static assertDriverConfig ( array $params, string $driver, array $fields, string $name = null, string $file = 'conf.php', string $variable = '$conf' ) | ||
$params | array | The configuration array with all parameters. |
$driver | string | The key name (in the configuration array) of the driver. |
$fields | array | An array with mandatory parameter names for this driver. |
$name | string | The clear text name of the driver. If not specified, the application name will be used. |
$file | string | The configuration file that should contain these settings. |
$variable | string | The name of the configuration variable. |
public static function assertDriverConfig($params, $driver, $fields, $name = null, $file = 'conf.php', $variable = '$conf')
{
global $registry;
// Don't generate a fatal error if we fail during or before
// Registry instantiation.
if (is_null($name)) {
$name = isset($registry) ? $registry->getApp() : '[unknown]';
}
$fileroot = isset($registry) ? $registry->get('fileroot') : '';
if (!is_array($params) || !count($params)) {
throw new Horde_Exception(sprintf(Horde_Core_Translation::t("No configuration information specified for %s."), $name) . "\n\n" . sprintf(Horde_Core_Translation::t("The file %s should contain some %s settings."), $fileroot . '/config/' . $file, sprintf("%s['%s']['params']", $variable, $driver)));
}
foreach ($fields as $field) {
if (!isset($params[$field])) {
throw new Horde_Exception(sprintf(Horde_Core_Translation::t("Required \"%s\" not specified in %s configuration."), $field, $name) . "\n\n" . sprintf(Horde_Core_Translation::t("The file %s should contain a %s setting."), $fileroot . '/config/' . $file, sprintf("%s['%s']['params']['%s']", $variable, $driver, $field)));
}
}
}
/** * Return the DB instance. * * @param string $type Either 'read' or 'rw'. * @param string $app The application. * @param mixed $dtype The type. If this is an array, this is used as * the configuration array. * * @return DB The singleton DB instance. * @throws Horde_Exception */ public function create($type = 'rw', $app = 'horde', $dtype = null) { global $registry; $sig = hash('sha1', serialize($type . '|' . $app . '|' . $dtype)); if (isset($this->_instances[$sig])) { return $this->_instances[$sig]; } $pushed = $app == 'horde' ? false : $registry->pushApp($app); $config = is_array($dtype) ? $dtype : $this->getConfig($dtype); if ($type == 'read' && !empty($config['splitread'])) { $config = array_merge($config, $config['read']); } Horde::assertDriverConfig($config, 'sql', array('charset', 'phptype')); /* Connect to the SQL server using the supplied parameters. */ $db = DB::connect($config, array('persistent' => !empty($config['persistent']), 'ssl' => !empty($config['ssl']))); if ($db instanceof PEAR_Error) { if ($pushed) { $registry->popApp(); } throw new Horde_Exception($db); } // Set DB portability options. $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); if ($pushed) { $registry->popApp(); } $this->_instances[$sig] = $db; return $db; }