本文整理汇总了PHP中Horde::assertDriverConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde::assertDriverConfig方法的具体用法?PHP Horde::assertDriverConfig怎么用?PHP Horde::assertDriverConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde
的用法示例。
在下文中一共展示了Horde::assertDriverConfig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* 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;
}
示例2: _connect
/**
* Attempts to open a connection to the LDAP server.
*
* @return boolean True on success.
* @throws Shout_Exception
*
* @access private
*/
protected function _connect()
{
if ($this->_connected) {
return;
}
if (!Horde_Util::extensionExists('ldap')) {
throw new Shout_Exception('Required LDAP extension not found.');
}
Horde::assertDriverConfig($this->_params, $this->_params['class'], array('hostspec', 'basedn', 'writedn'));
/* Open an unbound connection to the LDAP server */
$conn = ldap_connect($this->_params['hostspec'], $this->_params['port']);
if (!$conn) {
Horde::log(sprintf('Failed to open an LDAP connection to %s.', $this->_params['hostspec']), 'ERR');
throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.');
}
/* Set hte LDAP protocol version. */
if (isset($this->_params['version'])) {
$result = ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, $this->_params['version']);
if ($result === false) {
Horde::log(sprintf('Set LDAP protocol version to %d failed: [%d] %s', $this->_params['version'], ldap_errno($conn), ldap_error($conn)), 'WARN');
throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.', ldap_errno($conn));
}
}
/* Start TLS if we're using it. */
if (!empty($this->_params['tls'])) {
if (!@ldap_start_tls($conn)) {
Horde::log(sprintf('STARTTLS failed: [%d] %s', @ldap_errno($this->_ds), @ldap_error($this->_ds)), 'ERR');
}
}
/* If necessary, bind to the LDAP server as the user with search
* permissions. */
if (!empty($this->_params['searchdn'])) {
$bind = ldap_bind($conn, $this->_params['searchdn'], $this->_params['searchpw']);
if ($bind === false) {
Horde::log(sprintf('Bind to server %s:%d with DN %s failed: [%d] %s', $this->_params['hostspec'], $this->_params['port'], $this->_params['searchdn'], @ldap_errno($conn), @ldap_error($conn)), 'ERR');
throw new Shout_Exception('Internal LDAP error. Details have been logged for the administrator.', ldap_errno($conn));
}
}
/* Store the connection handle at the instance level. */
$this->_LDAP = $conn;
}
示例3: _connect
function _connect()
{
if (!is_null($this->_ldap)) {
return;
}
Horde::assertDriverConfig($this->_params['ldap'], 'storage', array('ldaphost', 'basedn', 'binddn', 'dn'));
if (!isset($this->_params['ldap']['bindpw'])) {
$this->_params['ldap']['bindpw'] = '';
}
$port = isset($this->_params['ldap']['port']) ? $this->_params['ldap']['port'] : 389;
$this->_ldap = ldap_connect($this->_params['ldap']['ldaphost'], $port);
if (!$this->_ldap) {
throw new Vilma_Exception("Unable to connect to LDAP server {$hostname} on {$port}");
}
$res = ldap_set_option($this->_ldap, LDAP_OPT_PROTOCOL_VERSION, $this->_params['ldap']['version']);
if (!$res) {
throw new Vilma_Exception(_("Unable to set LDAP protocol version"));
}
$res = ldap_bind($this->_ldap, $this->_params['ldap']['binddn'], $this->_params['ldap']['bindpw']);
if (!$res) {
throw new Vilma_Exception(_("Unable to bind to the LDAP server. Check authentication credentials."));
}
}
示例4: _connect
/**
* Attempts to open a connection to the LDAP server.
*
* @access private
*
* @return boolean True on success.
* @throws Beatnik_Exception
*
* @access private
*/
function _connect()
{
if (!$this->_connected) {
Horde::assertDriverConfig($this->_params, 'storage', array('hostspec', 'basedn', 'binddn', 'password', 'dn'));
$port = isset($this->_params['port']) ? $this->_params['port'] : 389;
$this->_LDAP = ldap_connect($this->_params['hostspec'], $port);
if (!$this->_LDAP) {
throw new Beatnik_Exception("Unable to connect to LDAP server {$hostname} on {$port}");
}
$res = ldap_set_option($this->_LDAP, LDAP_OPT_PROTOCOL_VERSION, $this->_params['version']);
if ($res === false) {
throw new Beatnik_Exception("Unable to set LDAP protocol version");
}
$res = ldap_bind($this->_LDAP, $this->_params['binddn'], $this->_params['password']);
if ($res === false) {
throw new Beatnik_Exception("Unable to bind to the LDAP server. Check authentication credentials.");
}
$this->_connected = true;
}
return true;
}