当前位置: 首页>>代码示例>>PHP>>正文


PHP self::connect方法代码示例

本文整理汇总了PHP中self::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP self::connect方法的具体用法?PHP self::connect怎么用?PHP self::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在self的用法示例。


在下文中一共展示了self::connect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: makeFromConfig

 /**
  * Initializes a new instance of the broker from specified parameters
  *
  * @param array $params An array with connect information
  * @return Keruald\Broker\AMQPBroker A connected instance of the broker
  */
 public static function makeFromConfig($params)
 {
     $instance = new self();
     $params += self::getDefaultValues();
     $instance->connect($params['host'], $params['port'], $params['username'], $params['password'], $params['vhost']);
     return $instance;
 }
开发者ID:keruald,项目名称:broker,代码行数:13,代码来源:AMQPBroker.php

示例2: connect

 public function connect($params = array())
 {
     if (!isset($this->status)) {
         $obj = new self($params);
         if ($obj->connect()) {
             $obj->status = SMTP_STATUS_CONNECTED;
         }
         return $obj;
     } else {
         if (!empty($GLOBALS['_CFG']['smtp_ssl'])) {
             $this->host = 'ssl://' . $this->host;
         }
         $this->connection = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
         if ($this->connection === false) {
             $this->errors[] = 'Access is denied.';
             return false;
         }
         @socket_set_timeout($this->connection, 0, 250000);
         $greeting = $this->get_data();
         if (is_resource($this->connection)) {
             $this->status = 2;
             return $this->auth ? $this->ehlo() : $this->helo();
         } else {
             log_write($errstr, __FILE__, __LINE__);
             $this->errors[] = 'Failed to connect to server: ' . $errstr;
             return false;
         }
     }
 }
开发者ID:netroby,项目名称:ecshop,代码行数:29,代码来源:cls_smtp.php

示例3: singleton

 public static function singleton()
 {
     if (is_null(self::$singleton)) {
         $driver = new self();
         return $driver->connect('config', array('dir' => CONFIG_PATH, 'humanReadable' => true));
     }
     return self::$singleton;
 }
开发者ID:oat-sa,项目名称:generis,代码行数:8,代码来源:class.ConfigDriver.php

示例4: initServer

 public static function initServer($config)
 {
     $class = new self();
     $class->connect($config['host'] . (empty($config['port']) ? '' : ':' . $config['port']), $config['user'], $config['pass']);
     if (!empty($config['dbname'])) {
         $class->select_db($config['dbname']);
     }
     return $class;
 }
开发者ID:ahmatjan,项目名称:EasyManage,代码行数:9,代码来源:mysql.class.php

示例5: getCache

 /**
  * @return bool
  */
 private static function getCache()
 {
     if (!Globals::get('MongularCache')) {
         return FALSE;
     }
     try {
         $cache = new self();
         if ($cache->connect()) {
             return $cache;
         }
         return FALSE;
     } catch (\Exception $e) {
         return FALSE;
     }
 }
开发者ID:mongular,项目名称:mongular,代码行数:18,代码来源:Cache.php

示例6: ldapImportGroup

 /** Converts an array of parameters into a query string to be appended to a URL.
  *
  * @param $group_dn        dn of the group to import
  * @param $options   array for
  *             - authldaps_id
  *             - entities_id where group must to be imported
  *             - is_recursive
  *
  * @return  nothing
  **/
 static function ldapImportGroup($group_dn, $options = array())
 {
     $config_ldap = new self();
     $res = $config_ldap->getFromDB($options['authldaps_id']);
     $ldap_users = array();
     $group_dn = $group_dn;
     // we prevent some delay...
     if (!$res) {
         return false;
     }
     //Connect to the directory
     $ds = $config_ldap->connect();
     if ($ds) {
         $group_infos = self::getGroupByDn($ds, stripslashes($group_dn));
         $group = new Group();
         if ($options['type'] == "groups") {
             return $group->add(array("name" => addslashes($group_infos["cn"][0]), "ldap_group_dn" => addslashes($group_infos["dn"]), "entities_id" => $options['entities_id'], "is_recursive" => $options['is_recursive']));
         }
         return $group->add(array("name" => addslashes($group_infos["cn"][0]), "ldap_field" => $config_ldap->fields["group_field"], "ldap_value" => addslashes($group_infos["dn"]), "entities_id" => $options['entities_id'], "is_recursive" => $options['is_recursive']));
     }
     return false;
 }
开发者ID:euqip,项目名称:glpi-smartcities,代码行数:32,代码来源:authldap.class.php

示例7: getAllUsers

 /** Get the list of LDAP users to add/synchronize
  *
  * @param $options array options
  *          - authldaps_id ID of the server to use
  *          - mode user to synchronise or add ?
  *          - ldap_filter ldap filter to use
  *          - basedn force basedn (default authldaps_id one)
  *          - order display order
  *          - operator operator used to limit user updates days
  *          - days number of days to limit (with operator)
  *          - script true if called by an external script
  * @param $results result stats
  * @param $limitexceeded limit exceeded exception
  *
  * @return  array of the user
  **/
 static function getAllUsers($options = array(), &$results, &$limitexceeded)
 {
     global $DB, $LANG, $CFG_GLPI;
     $config_ldap = new self();
     $res = $config_ldap->getFromDB($options['authldaps_id']);
     $values['order'] = 'DESC';
     $values['mode'] = self::ACTION_SYNCHRONIZE;
     $values['ldap_filter'] = '';
     $values['basedn'] = $config_ldap->fields['basedn'];
     $values['days'] = 0;
     $values['operator'] = '<';
     //Called by an external script or not
     $values['script'] = 0;
     // TODO change loop ? : foreach ($values...) if isset($options[...])
     foreach ($options as $option => $value) {
         // this test break mode detection - if ($value != '') {
         $values[$option] = $value;
         //}
     }
     $ldap_users = array();
     $limitexceeded = false;
     // we prevent some delay...
     if (!$res) {
         return false;
     }
     if ($values['order'] != "DESC") {
         $values['order'] = "ASC";
     }
     $ds = $config_ldap->connect();
     if ($ds) {
         //Search for ldap login AND modifyTimestamp,
         //which indicates the last update of the object in directory
         $attrs = array($config_ldap->fields['login_field'], "modifyTimestamp");
         // Tenter une recherche pour essayer de retrouver le DN
         if ($values['ldap_filter'] == '') {
             $filter = "(" . $config_ldap->fields['login_field'] . "=*)";
         } else {
             $filter = $values['ldap_filter'];
         }
         if ($values['script'] && $values['days']) {
             $filter_timestamp = self::addTimestampRestrictions($values['operator'], $values['days']);
             $filter = "(&{$filter} {$filter_timestamp})";
         }
         $sr = @ldap_search($ds, $values['basedn'], $filter, $attrs);
         if ($sr) {
             if (in_array(ldap_errno($ds), array(4, 11))) {
                 // openldap return 4 for Size limit exceeded
                 $limitexceeded = true;
             }
             $info = ldap_get_entries_clean($ds, $sr);
             if (in_array(ldap_errno($ds), array(4, 11))) {
                 $limitexceeded = true;
             }
             $user_infos = array();
             for ($ligne = 0; $ligne < $info["count"]; $ligne++) {
                 //If ldap add
                 if ($values['mode'] == self::ACTION_IMPORT) {
                     if (in_array($config_ldap->fields['login_field'], $info[$ligne])) {
                         $ldap_users[$info[$ligne][$config_ldap->fields['login_field']][0]] = $info[$ligne][$config_ldap->fields['login_field']][0];
                         $user_infos[$info[$ligne][$config_ldap->fields['login_field']][0]]["timestamp"] = self::ldapStamp2UnixStamp($info[$ligne]['modifytimestamp'][0], $config_ldap->fields['time_offset']);
                     }
                 } else {
                     //If ldap synchronisation
                     if (in_array($config_ldap->fields['login_field'], $info[$ligne])) {
                         $ldap_users[$info[$ligne][$config_ldap->fields['login_field']][0]] = self::ldapStamp2UnixStamp($info[$ligne]['modifytimestamp'][0], $config_ldap->fields['time_offset']);
                         $user_infos[$info[$ligne][$config_ldap->fields['login_field']][0]]["timestamp"] = self::ldapStamp2UnixStamp($info[$ligne]['modifytimestamp'][0], $config_ldap->fields['time_offset']);
                     }
                 }
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
     $glpi_users = array();
     $sql = "SELECT *\n                     FROM `glpi_users`";
     if ($values['mode'] != self::ACTION_IMPORT) {
         $sql .= " WHERE `authtype` IN (-1," . Auth::LDAP . "," . Auth::EXTERNAL . ", " . Auth::CAS . ")\n                         AND `auths_id` = '" . $options['authldaps_id'] . "'";
     }
     $sql .= " ORDER BY `name` " . $values['order'];
     foreach ($DB->request($sql) as $user) {
         //Ldap add : fill the array with the login of the user
         if ($values['mode'] == self::ACTION_IMPORT) {
//.........这里部分代码省略.........
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:101,代码来源:authldap.class.php

示例8: getConnection

 /**
  * @param array $params
  * @return UTIL_Ftp
  */
 public static function getConnection(array $params)
 {
     if (!function_exists('ftp_connect')) {
         throw new LogicException(self::ERROR_FTP_FUNCTION_IS_NOT_AVAILABLE);
     }
     if (empty($params['host'])) {
         throw new InvalidArgumentException(self::ERROR_EMPTY_HOST_PROVIDED);
     }
     if (empty($params['login']) || empty($params['password'])) {
         throw new InvalidArgumentException(self::ERROR_EMPTY_CREDENTIALS_PROVIDED);
     }
     $connection = new self();
     if (!empty($params['timeout'])) {
         $connection->setTimeout((int) $params['timeout']);
     }
     if (!$connection->connect(trim($params['host']), !empty($params['port']) ? (int) $params['port'] : 21)) {
         throw new LogicException(self::ERROR_CANT_CONNECT_TO_HOST);
     }
     if (!$connection->login(trim($params['login']), trim($params['password']))) {
         throw new LogicException(self::ERROR_INVALID_CREDENTIALS_PROVIDED);
     }
     $connection->init();
     return $connection;
 }
开发者ID:ZyXelP,项目名称:oxwall,代码行数:28,代码来源:ftp.php

示例9: Dispose

 public static function Dispose($cache_name, $options = array())
 {
     unset($options["save_on_destruction"]);
     $mc = new self($cache_name, $options);
     if (!$mc->is_dirty()) {
         return;
     }
     $mc->connect();
     if (!($res = $mc->mem_cache_instace->replace($mc->genKey(), $mc->get_internal_cache()))) {
         $res = $mc->mem_cache_instace->set($mc->genKey(), $mc->get_internal_cache());
     }
     if ($mc->mem_cache_instace->get($mc->genKey()) != $mc->get_internal_cache()) {
         $mc->disconnect();
         throw new \Exception("It seems race condition happened on saving cache updates, updates not saved!");
     }
     $mc->disconnect();
 }
开发者ID:dariushha,项目名称:zinux,代码行数:17,代码来源:memCache.php

示例10: getPersistence

 /**
  * 
  * @param common_ext_Extension $extension
  * @return common_persistence_KeyValuePersistence
  */
 public static function getPersistence(common_ext_Extension $extension)
 {
     $driver = new self($extension);
     return $driver->connect('config_' . $extension->getId(), array('dir' => CONFIG_PATH . $extension->getId(), 'humanReadable' => true));
 }
开发者ID:nagyist,项目名称:generis,代码行数:10,代码来源:class.ConfigDriver.php

示例11: init

 /**
  * Static initializer.
  *
  * Returns IMAP resource on success using the connect() method.
  *
  * For parameters, see constructor.
  *
  * @return resource|bool The IMAP resource on success. Boolean false on failure.
  */
 public static function init($args = array(), $connection = false)
 {
     $instance = new self($args, $connection);
     return $instance->connect();
 }
开发者ID:r-a-y,项目名称:bp-reply-by-email,代码行数:14,代码来源:bp-reply-by-email-connect.php

示例12: __test

 /** @ignore */
 public static function __test()
 {
     #parent::$debug = true;
     error_reporting(E_ALL);
     # Test basics and GET
     $c = new self('http://hunch.se/');
     $c->method = 'GeT';
     $c->url = 'http://apple.spotify.net/ping.php';
     $c->connect();
     assert($c->responseProtocol == '1.1');
     assert((int) ($c->responseStatus / 100) == 2);
     # Test POST
     $c->method = 'POST';
     $c->connect('unittest=1');
     # Test reset
     $c->url = 'http://apple.spotify.net/ping.php';
     $c->method = 'post';
     assert($c->connect('unittest=2'));
     # Test outputStream
     $c->outputStream = new StringOutputStream();
     $c->url = 'http://apple.spotify.net/ping.php?unittest=3';
     $c->method = 'GET';
     assert($c->connect());
     assert($c->outputStream->string != '');
     # Test auth
     #$c->method = 'GET';
     #$c->url = 'http://johndoe:foobar@apple.spotify.net/ui/?unittest=4';
     #$c->connect();
     # Test unsupported protocol error
     $c->url = 'azbx://something';
     try {
         $c->connect();
         assert(!'We should have gotten an exception thrown at us');
     } catch (Exception $e) {
         assert($e instanceof IllegalArgumentException);
     }
     # Test connection timeout handling
     $c->url = 'http://127.126.125.124/no-such-host/';
     $c->curlOptions[CURLOPT_CONNECTTIMEOUT] = 1;
     try {
         $c->connect();
         assert(!'We should have gotten an exception thrown at us');
     } catch (Exception $e) {
         assert($e instanceof ConnectException);
     }
 }
开发者ID:rsms,项目名称:phpab,代码行数:47,代码来源:HTTPConnection.php

示例13: getConnection

 /**
  * @param array $params
  * @return UTIL_Ftp
  */
 public static function getConnection(array $params)
 {
     if (empty($params['host'])) {
         throw new InvalidArgumentException('Empty host provided for connection');
     }
     $connection = new self();
     if (!empty($params['timeout'])) {
         $connection->setTimeout((int) $params['timeout']);
     }
     $connected = $connection->connect(trim($params['host']), !empty($params['port']) ? (int) $params['port'] : 21);
     if (!$connected) {
         throw new LogicException("Can't connect to host `" . trim($params['host']) . "` by FTP");
     }
     if (!empty($params['login']) && !empty($params['password'])) {
         $connection->login(trim($params['login']), trim($params['password']));
     }
     $connection->init();
     return $connection;
 }
开发者ID:vazahat,项目名称:dudex,代码行数:23,代码来源:ftp.php


注:本文中的self::connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。