本文整理汇总了PHP中Q_Request::userAgentInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Request::userAgentInfo方法的具体用法?PHP Q_Request::userAgentInfo怎么用?PHP Q_Request::userAgentInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q_Request
的用法示例。
在下文中一共展示了Q_Request::userAgentInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Adds a device to the system, after sending a test notification to it
* @param {array} $device
* @param {string} $device.userId
* @param {string} $device.deviceId
* @param {string} [$device.formFactor]
* @param {string} [$device.platform]
* @param {string} [$device.version]
* @param {string} [$device.sessionId]
* @param {boolean} [$device.sandbox]
* @param {string} [$device.passphrase]
* @param {boolean} [$skipNotification=false] if true, skips sending notification
* @return {Users_Device}
*/
static function add($device, $skipNotification = false)
{
Q_Valid::requireFields(array('userId', 'deviceId'), $device, true);
$userId = $device['userId'];
$deviceId = $device['deviceId'];
if (!$skipNotification) {
$app = Q::app();
$sandbox = Q::ifset($device, 'sandbox', null);
if (!isset($sandbox)) {
$sandbox = Q_Config::get($app, "cordova", "ios", "sandbox", false);
}
$env = $sandbox ? ApnsPHP_Abstract::ENVIRONMENT_SANDBOX : ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION;
$s = $sandbox ? 'sandbox' : 'production';
$cert = APP_LOCAL_DIR . DS . 'Users' . DS . 'certs' . DS . $app . DS . $s . DS . 'bundle.pem';
$authority = USERS_PLUGIN_FILES_DIR . DS . 'Users' . DS . 'certs' . DS . 'EntrustRootCA.pem';
$logger = new Users_ApnsPHP_Logger();
$push = new ApnsPHP_Push($env, $cert);
$push->setLogger($logger);
$push->setRootCertificationAuthority($authority);
if (isset($device['passphrase'])) {
$push->setProviderCertificatePassphrase($device['passphrase']);
}
$push->connect();
$message = new ApnsPHP_Message($deviceId);
$message->setCustomIdentifier('Users_Device-adding');
$message->setBadge(0);
$message->setText(Q_Config::get($app, "cordova", "ios", "device", "text", "Notifications have been enabled"));
$message->setCustomProperty('userId', $userId);
$message->setExpiry(5);
$push->add($message);
$push->send();
$push->disconnect();
$errors = $push->getErrors();
if (!empty($errors)) {
$result = reset($errors);
throw new Users_Exception_DeviceNotification($result['ERRORS'][0]);
}
}
$sessionId = Q_Session::id();
$user = Users::loggedInUser();
$info = array_merge(Q_Request::userAgentInfo(), array('sessionId' => $sessionId, 'userId' => $user ? $user->id : null, 'deviceId' => null));
$device2 = Q::take($device, $info);
$d = new Users_Device($device2);
$d->save(true);
if ($sessionId) {
$s = new Users_Session();
$s->id = $sessionId;
if (!$s->retrieve()) {
$s->deviceId = $deviceId;
}
}
$_SESSION['Users']['deviceId'] = $deviceId;
$device2['Q/method'] = 'Users/device';
Q_Utils::sendToNode($device2);
return $d;
}
示例2: start
//.........这里部分代码省略.........
/**
* @event Q/session/generate {before}
* @param {string} id An invalid id, if any, that was passed by the client
* @return {boolean}
*/
if (false === Q::event('Q/session/generate', compact('id'), 'before')) {
return false;
}
$id = self::generateId();
}
try {
if ($id) {
self::processDbInfo();
if (self::$session_db_connection) {
$id_field = self::$session_db_id_field;
$data_field = self::$session_db_data_field;
$updated_field = self::$session_db_updated_field;
$duration_field = self::$session_db_duration_field;
$class = self::$session_db_row_class;
$row = new $class();
$row->{$id_field} = $id;
if ($row->retrieve()) {
self::$session_db_row = $row;
} else {
// Start a new session with our own id
$id = $row->{$id_field} = self::generateId();
$row->{$data_field} = "";
$row->{$updated_field} = date('Y-m-d H:i:s');
$row->{$duration_field} = Q_Config::get('Q', 'session', 'durations', Q_Request::formFactor(), Q_Config::expect('Q', 'session', 'durations', 'session'));
if (false !== Q::event('Q/session/save', array('row' => $row, 'id_field' => $id_field, 'data_field' => $data_field, 'updated_field' => $updated_field, 'duration_field' => $duration_field, 'inserting' => true), 'before')) {
$row->save();
self::id($row->{$id_field});
// this sets the session cookie as well
self::$session_db_row = $row;
}
}
}
self::id($id);
}
if (!empty($_SERVER['HTTP_HOST'])) {
$durationName = self::durationName();
$duration = Q_Config::get('Q', 'session', 'durations', $durationName, 0);
Q_Response::setCookie(self::name(), $id, $duration ? time() + $duration : 0);
} else {
if (empty($_SESSION)) {
$_SESSION = array();
}
}
ini_set('session.use_cookies', 0);
// we are gonna handle the cookies, thanks
session_cache_limiter('');
// don't send the cache limiter headers either
session_start();
} catch (Exception $e) {
$app = Q_Config::get('Q', 'app', null);
$prefix = $app ? "{$app}/" : '';
if (empty($_SERVER['HTTP_HOST'])) {
echo "Warning: Ignoring Q_Session::start() called before running {$prefix}scripts/Q/install.php --all" . PHP_EOL;
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
if (is_callable(array($e, 'getTraceAsStringEx'))) {
$trace_string = $e->getTraceAsStringEx();
} else {
$trace_string = $e->getTraceAsString();
}
echo "{$message}\n(in {$file} line {$line})\n{$trace_string}" . PHP_EOL;
} else {
if (is_callable('apc_clear_cache')) {
apc_clear_cache('user');
}
Q::log($e);
throw new Q_Exception("Please run {$prefix}scripts/Q/install.php --all");
}
}
// merge in all the stuff that was added to $_SESSION
// before we started it.
if (isset($pre_SESSION)) {
foreach ($pre_SESSION as $k => $v) {
$_SESSION[$k] = $v;
}
}
if (isset($_SESSION['Q']['notices'])) {
foreach ($_SESSION['Q']['notices'] as $k => $v) {
Q_Response::setNotice($k, $v);
}
}
if (!empty($_SESSION['Q']['terminated'])) {
throw new Q_Exception_SessionTerminated(array('id' => Q_Session::id()));
}
if (Q_Config::get('Q', 'session', 'userAgentInfo', null)) {
$arr = isset($_SESSION['Q']) ? $_SESSION['Q'] : array();
$_SESSION['Q'] = array_merge($arr, Q_Request::userAgentInfo());
}
/**
* @event Q/session/start {after}
*/
Q::event('Q/session/start', array(), 'after');
return true;
}