本文整理汇总了PHP中QuickBooks_Utilities::parseDSN方法的典型用法代码示例。如果您正苦于以下问题:PHP QuickBooks_Utilities::parseDSN方法的具体用法?PHP QuickBooks_Utilities::parseDSN怎么用?PHP QuickBooks_Utilities::parseDSN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuickBooks_Utilities
的用法示例。
在下文中一共展示了QuickBooks_Utilities::parseDSN方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create an instance of a driver class from a DSN connection string *or* a connection resource
*
* You can actually pass in *either* a DSN-style connection string OR an already connected database resource
* - mysql://user:pass@localhost:port/database
* - $var (Resource ID #XYZ, valid MySQL connection resource)
*
* @param mixed $dsn_or_conn A DSN-style connection string or a PHP resource
* @param array $config An array of configuration options for the driver
* @param array $hooks An array mapping hooks to user-defined hook functions to call
* @param integer $log_level
* @return object A class instance, a child class of QuickBooks_Driver
*/
public static function create($dsn_or_conn, $config = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL)
{
static $instances = array();
if (!is_array($hooks)) {
$hooks = array();
}
$key = (string) $dsn_or_conn . serialize($config) . serialize($hooks) . $log_level;
if (!isset($instances[$key])) {
if (is_resource($dsn_or_conn)) {
$scheme = current(explode(' ', get_resource_type($dsn_or_conn)));
} else {
$scheme = QuickBooks_Utilities::parseDSN($dsn_or_conn, array(), 'scheme');
}
if (false !== strpos($scheme, 'sql')) {
$scheme = 'SQL_' . $scheme;
}
$class = 'QuickBooks_Driver_' . ucfirst(strtolower($scheme));
$file = 'QuickBooks/Driver/' . str_replace(' ', '/', ucwords(str_replace('_', ' ', strtolower($scheme)))) . '.php';
require_once $file;
if (class_exists($class)) {
$Driver = new $class($dsn_or_conn, $config);
$Driver->registerHooks($hooks);
$Driver->setLogLevel($log_level);
// @todo Ugh this is really ugly... maybe have $log_level passed in as a parameter? Not really a driver option at all?
//if (isset($config['log_level']))
//{
// $driver->setLogLevel($config['log_level']);
//}
$instances[$key] = $Driver;
} else {
$instances[$key] = null;
}
}
return $instances[$key];
}
示例2: __construct
/**
* Create a new PostgreSQL database authenticator
*
* @param string $dsn A DSN-style connection string for PostgreSQL (i.e.: pgsql://username:password@hostname:port/database)
*/
public function __construct($dsn)
{
$conn_defaults = array('scheme' => 'pgsql', 'user' => 'pgsql', 'pass' => '', 'host' => 'localhost', 'port' => 5432, 'path' => '/quickbooks', 'query' => '');
$param_defaults = array('table_name' => 'quickbooks_user', 'field_username' => 'qb_username', 'field_password' => 'qb_password', 'crypt_function' => 'sha1', 'field_company_file' => null, 'field_wait_before_next_update' => null, 'field_min_run_every_n_seconds' => null);
// mysql://user:pass@localhost:port/database?table_name=quickbooks_user&field_username=username&field_password=password&crypt_function=md5
$parse = QuickBooks_Utilities::parseDSN($dsn, $conn_defaults);
$vars = array();
parse_str($parse['query'], $vars);
$param_defaults = array_merge($param_defaults, $vars);
$conn_str = '';
if (strlen($parse['host'])) {
$conn_str .= ' host=' . $parse['host'];
}
if (strlen($parse['port'])) {
$conn_str .= ' port=' . (int) $parse['port'];
}
if (strlen($parse['user'])) {
$conn_str .= ' user=' . $parse['user'];
}
if (strlen($parse['pass'])) {
$conn_str .= ' password=' . $parse['pass'];
}
$conn_str .= ' dbname=' . substr($parse['path'], 1);
$this->_conn = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW);
$this->_table_name = pg_escape_string($this->_conn, $param_defaults['table_name']);
$this->_field_username = pg_escape_string($this->_conn, $param_defaults['field_username']);
$this->_field_password = pg_escape_string($this->_conn, $param_defaults['field_password']);
$this->_crypt_function = $param_defaults['crypt_function'];
$this->_field_company_file = $param_defaults['field_company_file'];
$this->_field_wait_before_next_update = $param_defaults['field_wait_before_next_update'];
$this->_field_min_run_every_n_seconds = $param_defaults['field_min_run_every_n_seconds'];
}
示例3: create
public static function create($dsn_or_conn, $mode, $user, $action, $config = array())
{
static $instances = array();
$key = (string) $dsn_or_conn . ',' . $mode . ',' . $user . ',' . $action . ',' . serialize($config);
if (!isset($instances[$key])) {
if (is_resource($dsn_or_conn)) {
$scheme = current(explode(' ', get_resource_type($dsn_or_conn)));
} else {
$scheme = QuickBooks_Utilities::parseDSN($dsn_or_conn, array(), 'scheme');
}
if (false !== strpos($scheme, 'sql')) {
$scheme = 'SQL_' . $scheme;
}
$class = 'QuickBooks_Transport_' . ucfirst(strtolower($scheme));
$file = 'QuickBooks/Transport/' . str_replace(' ', '/', ucwords(str_replace('_', ' ', strtolower($scheme)))) . '.php';
require_once $file;
if (class_exists($class)) {
$Transport = new $class($dsn_or_conn, $mode, $user, $action, $config);
$instances[$key] = $Transport;
} else {
$instances[$key] = null;
}
}
return $instances[$key];
}
示例4: __construct
/**
* Create a new authentication handler
*
* @param string $dsn A DSN-style string indicating the function name and other parameters, i.e.: function://my_function_name?param1=value1¶m2=value2
*/
public function __construct($dsn)
{
$conn_defaults = array('scheme' => 'function', 'user' => '', 'pass' => '', 'host' => 'your_function_name', 'port' => 0, 'path' => '', 'query' => '');
// function://my_function_name?param1=value1¶m2=value2
$parse = QuickBooks_Utilities::parseDSN($dsn, $conn_defaults);
$vars = array();
parse_str($parse['query'], $vars);
$this->_function = $parse['host'];
$this->_params = array_merge($vars);
}
示例5: __construct
/**
* Create a new authentication handler
*
* @param string $dsn DSN-style connection string, something like: htpasswd:///path/to/your/htpasswd/file.htpasswd
*/
public function __construct($dsn)
{
$conn_defaults = array('scheme' => 'htpasswd', 'user' => '', 'pass' => '', 'host' => 'localhost', 'port' => 3306, 'path' => '/path/to/htpasswd', 'query' => '');
// htpasswd:///database?table_name=quickbooks_user&field_username=username&field_password=password&crypt_function=md5
$parse = QuickBooks_Utilities::parseDSN($dsn, $conn_defaults);
$this->_accounts = array();
if (is_file($parse['path']) and $lines = file($parse['path'])) {
foreach ($lines as $line) {
$explode = explode(':', trim($line));
$this->_accounts[$explode[0]] = $explode[1];
}
}
}
示例6: create
/**
* Create an instance of a driver class from a DSN connection string *or* a connection resource
*
* You can actually pass in *either* a DSN-style connection string OR an already connected database resource
* - mysql://user:pass@localhost:port/database
* - $var (Resource ID #XYZ, valid MySQL connection resource)
*
* @param mixed $dsn_or_conn A DSN-style connection string or a PHP resource
* @param array $config An array of configuration options for the driver
* @param array $hooks An array mapping hooks to user-defined hook functions to call
* @param integer $log_level
* @return object A class instance, a child class of QuickBooks_Driver
*/
public static function create($dsn_or_conn, $config = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL)
{
static $instances = array();
if (!is_array($hooks)) {
$hooks = array();
}
// Do not serialize the $hooks because they might contain non-serializeable objects
$key = (string) $dsn_or_conn . serialize($config) . $log_level;
if (!isset($instances[$key])) {
if (is_resource($dsn_or_conn)) {
$scheme = current(explode(' ', get_resource_type($dsn_or_conn)));
} else {
$scheme = QuickBooks_Utilities::parseDSN($dsn_or_conn, array(), 'scheme');
}
if (false !== strpos($scheme, 'sql')) {
$scheme = 'Sql_' . ucfirst(strtolower($scheme));
} else {
$scheme = ucfirst(strtolower($scheme));
}
$class = 'QuickBooks_Driver_' . $scheme;
$file = '/QuickBooks/Driver/' . str_replace(' ', '/', ucwords(str_replace('_', ' ', strtolower($scheme)))) . '.php';
//print('class: ' . $class . "\n");
//print('file: ' . $file . "\n");
QuickBooks_Loader::load($file);
if (class_exists($class)) {
$Driver = new $class($dsn_or_conn, $config);
$Driver->registerHooks($hooks);
$Driver->setLogLevel($log_level);
/*
static $static = 0;
$static++;
print('Constructed new instance ' . $static . ' [' . $key . ']' . "\n");
mysql_query("INSERT INTO quickbooks_log ( msg, log_datetime ) VALUES ( 'Here is my " . $static . " key: " . $key . "', NOW() )");
//print_r($hooks);
*/
// @todo Ugh this is really ugly... maybe have $log_level passed in as a parameter? Not really a driver option at all?
//if (isset($config['log_level']))
//{
// $driver->setLogLevel($config['log_level']);
//}
$instances[$key] = $Driver;
} else {
$instances[$key] = null;
}
}
return $instances[$key];
}
示例7: __construct
/**
* Create a new instance of the MySQL Web Connector authenticator
*
* @param string $dsn A DSN-style MySQL connection string (i.e.: mysql://your-username:your-password@your-localhost:port/your-database)
*/
public function __construct($dsn)
{
$conn_defaults = array('scheme' => 'mysql', 'user' => 'root', 'pass' => '', 'host' => 'localhost', 'port' => 3306, 'path' => '/quickbooks', 'query' => '');
$param_defaults = array('table_name' => 'quickbooks_user', 'field_username' => 'qb_username', 'field_password' => 'qb_password', 'field_company_file' => null, 'field_wait_before_next_update' => null, 'field_min_run_every_n_seconds' => null, 'crypt_function' => 'sha1');
// mysql://user:pass@localhost:port/database?table_name=quickbooks_user&field_username=username&field_password=password&crypt_function=md5
$parse = QuickBooks_Utilities::parseDSN($dsn, $conn_defaults);
$vars = array();
parse_str($parse['query'], $vars);
$param_defaults = array_merge($param_defaults, $vars);
$this->_conn = mysql_connect($parse['host'] . ':' . $parse['port'], $parse['user'], $parse['pass'], true);
mysql_select_db(substr($parse['path'], 1), $this->_conn);
$this->_table_name = mysql_real_escape_string($param_defaults['table_name'], $this->_conn);
$this->_field_username = mysql_real_escape_string($param_defaults['field_username'], $this->_conn);
$this->_field_password = mysql_real_escape_string($param_defaults['field_password'], $this->_conn);
$this->_crypt_function = $param_defaults['crypt_function'];
$this->_field_company_file = $param_defaults['field_company_file'];
$this->_field_wait_before_next_update = $param_defaults['field_wait_before_next_update'];
$this->_field_min_run_every_n_seconds = $param_defaults['field_min_run_every_n_seconds'];
}
示例8: __construct
/**
* Create a new authentication handler
*
* @param string $dsn DSN-style connection string, something like: htpasswd:///path/to/your/htpasswd/file.htpasswd
*/
public function __construct($dsn)
{
ini_set('auto_detect_line_endings', true);
$conn_defaults = array('scheme' => 'csv', 'user' => '', 'pass' => '', 'host' => '', 'port' => '', 'path' => '/path/to/file.csv', 'query' => '');
// htpasswd:///database?table_name=quickbooks_user&field_username=username&field_password=password&crypt_function=md5
$parse = QuickBooks_Utilities::parseDSN($dsn, $conn_defaults);
$this->_accounts = array();
if (is_file($parse['path']) and $fp = fopen($parse['path'], 'r')) {
while (false !== ($arr = fgetcsv($fp, 1000, ','))) {
if (empty($arr[0]) or empty($arr[1])) {
continue;
}
for ($i = 2; $i < 10; $i++) {
if (empty($arr[$i])) {
$arr[$i] = '';
}
}
$username = trim($arr[0]);
$this->_accounts[$username] = $arr;
}
}
}
示例9: __construct
/**
* Create a new MySQL back-end driver
*
* @param string $dsn A DSN-style connection string (i.e.: "mysql://your-mysql-username:your-mysql-password@your-mysql-host:port/your-mysql-database")
* @param array $config Configuration options for the driver (not currently supported)
*/
public function __construct($dsn_or_conn, $config)
{
$config = $this->_defaults($config);
$this->_log_level = (int) $config['log_level'];
if (is_resource($dsn_or_conn)) {
$this->_conn = $dsn_or_conn;
} else {
$defaults = array('scheme' => 'mysql', 'host' => 'localhost', 'port' => 3306, 'user' => 'root', 'pass' => '', 'path' => '/quickbooks');
$parse = QuickBooks_Utilities::parseDSN($dsn_or_conn, $defaults);
$this->_connect($parse['host'], $parse['port'], $parse['user'], $parse['pass'], substr($parse['path'], 1), $config['new_link'], $config['client_flags']);
}
// Call the parent constructor too
parent::__construct($dsn_or_conn, $config);
}
示例10: authenticate
/**
* Authenticate method for the QuickBooks Web Connector SOAP service
*
* The authenticate method is called when the Web Connector establishes a
* connection with the SOAP server in order to ensure that there is work to
* do and that the Web Connector is allowed to connect/that it actually is
* the Web Connector that is connecting and sending us messages.
*
* The stdClass object that is received as a parameter will have two
* members:
* - strUserName The username provided in the QWC file to the Web Connector
* - strPassword The password the end-user enters into the QuickBooks Web Connector application
*
* The return object should be an array with two elements. The first
* element is a generated login ticket (or an empty string if the login
* failed) and the second string is either "none" (for successful log-ins
* with nothing to do in the queue) or "nvu" if the login failed.
*
* The following user-defined hooks are invoked:
* - QUICKBOOKS_HANDLERS_HOOK_AUTHENTICATE
* - QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS
* - QUICKBOOKS_HANDLERS_HOOK_LOGINFAILURE
*
* @param stdClass $obj The SOAP object that gets sent by the Web Connector
* @return QuickBooks_Result_Authenticate A container object to send back to the Web Connector
*/
public function authenticate($obj)
{
$this->_driver->log('authenticate()', '', QUICKBOOKS_LOG_VERBOSE);
$ticket = '';
$status = '';
// Authenticate login hook
$hookdata = array('username' => $obj->strUserName, 'password' => $obj->strPassword);
$hookerr = '';
$this->_callHook($ticket, QUICKBOOKS_HANDLERS_HOOK_AUTHENTICATE, null, null, null, null, $hookerr, null, array(), $hookdata);
// Remote address allow/deny
if (false == $this->_checkRemote($_SERVER['REMOTE_ADDR'], $this->_config['allow_remote_addr'], $this->_config['deny_remote_addr'])) {
$this->_driver->log('Connection from remote address rejected: ' . $_SERVER['REMOTE_ADDR'], null, QUICKBOOKS_LOG_VERBOSE);
return new QuickBooks_Result_Authenticate('', 'nvu', null, null);
}
$override_dsn = $this->_config['authenticate_dsn'];
$auth = null;
if (strlen($override_dsn)) {
$parse = QuickBooks_Utilities::parseDSN($override_dsn);
$class = 'QuickBooks_Authenticate_' . $parse['scheme'];
require_once 'QuickBooks/Authenticate/' . ucfirst(strtolower($parse['scheme'])) . '.php';
$auth = new $class($override_dsn);
}
$company_file = null;
$wait_before_next_update = null;
$min_run_every_n_seconds = null;
$customauth_company_file = null;
$customauth_wait_before_next_update = null;
$customauth_min_run_every_n_seconds = null;
if (strlen($override_dsn) and is_object($auth)) {
if ($auth->authenticate($obj->strUserName, $obj->strPassword, $customauth_company_file, $customauth_wait_before_next_update, $customauth_min_run_every_n_seconds) and $ticket = $this->_driver->authLogin($obj->strUserName, $obj->strPassword, $company_file, $wait_before_next_update, $min_run_every_n_seconds, true)) {
$this->_driver->log('Login (' . $parse['scheme'] . '): ' . $obj->strUserName, $ticket, QUICKBOOKS_LOG_DEBUG);
if ($customauth_company_file) {
$status = $customauth_company_file;
} else {
if ($company_file) {
$status = $company_file;
} else {
if ($this->_config['qb_company_file']) {
$status = $this->_config['qb_company_file'];
}
}
}
if ((int) $customauth_wait_before_next_update) {
$wait_before_next_update = (int) $customauth_wait_before_next_update;
} else {
if ((int) $wait_before_next_update) {
} else {
if ((int) $this->_config['qbwc_wait_before_next_update']) {
$wait_before_next_update = (int) $this->_config['qbwc_wait_before_next_update'];
}
}
}
if ((int) $customauth_min_run_every_n_seconds) {
$min_run_every_n_seconds = (int) $customauth_min_run_every_n_seconds;
} else {
if ((int) $min_run_every_n_seconds) {
} else {
if ((int) $this->_config['qbwc_min_run_every_n_seconds']) {
$min_run_every_n_seconds = (int) $this->_config['qbwc_min_run_every_n_seconds'];
}
}
}
// Call login hook
$hookdata = array('authenticate_dsn' => $override_dsn, 'username' => $obj->strUserName, 'password' => $obj->strPassword, 'ticket' => $ticket, 'qb_company_file' => $status, 'qbwc_wait_before_next_update' => $wait_before_next_update, 'qbwc_min_run_every_n_seconds' => $min_run_every_n_seconds);
$hookerr = '';
$this->_callHook($ticket, QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS, null, null, null, null, $hookerr, null, array(), $hookdata);
// Move any recurring events that are due to the queue table
$this->_handleRecurringEvents($ticket);
if (!$this->_driver->queueDequeue($obj->strUserName)) {
$status = 'none';
}
// Login success (with a custom login handler)!
} else {
$this->_driver->log('Login failed (' . $parse['scheme'] . '): ' . $obj->strUserName, '', QUICKBOOKS_LOG_DEBUG);
//.........这里部分代码省略.........
示例11: _outputFsockopen
public function _outputFsockopen($data)
{
$defaults = array('scheme' => 'http', 'port' => 80, 'path' => '/');
$parse = QuickBooks_Utilities::parseDSN($this->_dsn, $defaults);
$socket_host = $parse['host'];
$socket_port = $parse['port'];
if ($parse['scheme'] == 'https') {
$socket_host = 'ssl://' . $parse['host'];
if ($socket_port == 80) {
$socket_port = 443;
}
}
$fp = fsockopen($socket_host, $socket_port);
fputs($fp, 'POST ' . $parse['path'] . ' HTTP/1.0' . "\r\n");
fputs($fp, 'Host: ' . $parse['host'] . "\r\n");
fputs($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
fputs($fp, 'Content-Length: ' . strlen($data) . "\r\n");
fputs($fp, 'Connection: close' . "\r\n");
fputs($fp, "\r\n");
fputs($fp, $data);
$bytes = 0;
$resp = '';
while (!feof($fp) and $bytes < 1000) {
$tmp = fgets($fp, 128);
$bytes += strlen($tmp);
$resp .= $tmp;
}
//print($resp);
fclose($fp);
return true;
}
示例12: __construct
/**
* Create a new MySQL back-end driver
*
* @param string $dsn A DSN-style connection string (i.e.: "mysql://your-mysql-username:your-mysql-password@your-mysql-host:port/your-mysql-database")
* @param array $config Configuration options for the driver (not currently supported)
*/
public function __construct($dsn_or_conn, $config)
{
$config = $this->_defaults($config);
$this->_log_level = (int) $config['log_level'];
if (is_resource($dsn_or_conn)) {
$this->_conn = $dsn_or_conn;
} else {
$trim = false;
if (false === strpos($dsn_or_conn, ':///')) {
$dsn_or_conn = str_replace('://', '://localhost/', $dsn_or_conn);
$trim = true;
}
$defaults = array('scheme' => 'mysql', 'host' => 'localhost', 'port' => 3306, 'user' => 'root', 'pass' => '', 'path' => '/quickbooks');
$parse = QuickBooks_Utilities::parseDSN($dsn_or_conn, $defaults);
if ($trim) {
$parse['path'] = substr($parse['path'], 1);
}
//print_r($parse);
//exit;
$this->_connect($parse['host'], $parse['port'], $parse['user'], $parse['pass'], $parse['path'], $config['new_link'], $config['client_flags']);
}
// Call the parent constructor too
parent::__construct($dsn_or_conn, $config);
}