assertDriverConfig() публичный статический Метод

Checks if all necessary parameters for a driver configuration are set and throws a fatal error with a detailed explanation how to fix this, if something is missing.
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.
Пример #1
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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;
 }