本文整理汇总了PHP中Token::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::add方法的具体用法?PHP Token::add怎么用?PHP Token::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback
public static function callback()
{
//Get the username
$username = $_GET['username'];
//Save it inside as an access_token
Token::add(self::name, $_SESSION['userid'], $username);
redirect_to('/');
}
示例2: parseLine
/**
* Parse the token line using a PCRE
*
* @param string $line
* @return array|FALSE
*/
private function parseLine($line)
{
if (preg_match($this->_linePattern, $line, $parts)) {
$token = new Token($parts['name'], isset($parts['value']) ? $this->unescape($parts['value']) : '');
if (!empty($parts['parameters']) && preg_match_all($this->_parametersPattern, $parts['parameters'], $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
if (empty($match['paramName'])) {
continue;
}
$token->add($match['paramName'], $this->parseValue($match['paramValue']));
}
}
return $token;
}
return NULL;
}
示例3: callback
public static function callback()
{
global $HTTP_CONFIG;
//exchange the code you get for a access_token
$code = $_GET['code'];
$request = new HTTP_Request2(self::ACCESS_TOKEN_URL);
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig($HTTP_CONFIG);
$request->addPostParameter(['client_id' => GITHUB_APP_ID, 'client_secret' => GITHUB_APP_SECRET, 'code' => $code]);
$request->setHeader('Accept', 'application/json');
$response = $request->send();
$response = json_decode($response->getBody());
$access_token = $response->access_token;
//Use this access token to get user details
$request = new HTTP_Request2(self::USER_URL . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
$response = $request->send()->getBody();
$userid = json_decode($response)->login;
//get the userid
//If such a user already exists in the database
//Just log him in and don't touch the access_token
$already_present_token = Token::get('github', $userid);
if ($already_present_token) {
$_SESSION['userid'] = $userid;
redirect_to('/');
}
if (defined('GITHUB_ORGANIZATION')) {
// perform the organization check
$request = new HTTP_Request2(json_decode($response)->organizations_url . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
$response = $request->send()->getBody();
//List of organizations
$organizations_list = array_map(function ($repo) {
return $repo->login;
}, json_decode($response));
if (in_array(GITHUB_ORGANIZATION, $organizations_list)) {
$_SESSION['userid'] = $userid;
Token::add('github', $userid, $access_token);
} else {
throw new Exception('You are not in the listed members.');
}
} else {
$_SESSION['userid'] = $userid;
Token::add('github', $userid, $access_token);
}
redirect_to('/');
}
示例4: callback
public static function callback()
{
global $HTTP_CONFIG;
//Check state for csrf attack
if ($_SESSION['state'] != $_GET['state']) {
throw new Exception('Invalid Request. Please try again.');
}
//Get the access code
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/login/facebook/callback';
$token_url = 'https://graph.facebook.com/oauth/access_token?' . 'client_id=' . FACEBOOK_APP_ID . '&redirect_uri=' . urlencode($redirect_uri) . '&client_secret=' . FACEBOOK_APP_SECRET . '&code=' . $_GET['code'];
//Send the request
$request = new HTTP_Request2($token_url);
$request->setConfig($HTTP_CONFIG);
$response = $request->send()->getBody();
parse_str($response, $params);
//Save it inside as an access_token
Token::add(self::name, $_SESSION['userid'], $params['access_token']);
redirect_to('/');
}
示例5: testPhpTokens
public function testPhpTokens()
{
$this->assertPhpToken('abstract', Token::_abstract());
$this->assertPhpToken('array', Token::_array());
$this->assertPhpToken('as', Token::_as());
$this->assertPhpToken('break', Token::_break());
$this->assertPhpToken('callable', Token::_callable());
$this->assertPhpToken('case', Token::_case());
$this->assertPhpToken('catch', Token::_catch());
$this->assertPhpToken('class', Token::_class());
$this->assertPhpToken('clone', Token::_clone());
$this->assertPhpToken('const', Token::_const());
$this->assertPhpToken('continue', Token::_continue());
$this->assertPhpToken('declare', Token::_declare());
$this->assertPhpToken('default', Token::_default());
$this->assertPhpToken('die', Token::_die());
$this->assertPhpToken('do', Token::_do());
$this->assertPhpToken('echo', Token::_echo());
$this->assertPhpToken('else', Token::_else());
$this->assertPhpToken('elseif', Token::_elseIf());
$this->assertPhpToken('empty', Token::_empty());
$this->assertPhpToken('enddeclare', Token::_endDeclare());
$this->assertPhpToken('endfor', Token::_endFor());
$this->assertPhpToken('endforeach', Token::_endForeach());
$this->assertPhpToken('endif', Token::_endIf());
$this->assertPhpToken('endswitch', Token::_endSwitch());
$this->assertPhpToken('endwhile', Token::_endWhile());
$this->assertPhpToken('eval', Token::_eval());
$this->assertPhpToken('exit', Token::_exit());
$this->assertPhpToken('extends', Token::_extends());
$this->assertPhpToken('final', Token::_final());
$this->assertPhpToken('for', Token::_for());
$this->assertPhpToken('foreach', Token::_foreach());
$this->assertPhpToken('function', Token::_function());
$this->assertPhpToken('global', Token::_global());
$this->assertPhpToken('goto', Token::_goto());
$this->assertPhpToken('if', Token::_if());
$this->assertPhpToken('implements', Token::_implements());
$this->assertPhpToken('include', Token::_include());
$this->assertPhpToken('include_once', Token::_includeOnce());
$this->assertPhpToken('instanceof', Token::_instanceOf());
$this->assertPhpToken('insteadof', Token::_insteadOf());
$this->assertPhpToken('interface', Token::_interface());
$this->assertPhpToken('isset', Token::_isset());
$this->assertPhpToken('list', Token::_list());
$this->assertPhpToken('namespace', Token::_namespace());
$this->assertPhpToken('new', Token::_new());
$this->assertPhpToken('print', Token::_print());
$this->assertPhpToken('private', Token::_private());
$this->assertPhpToken('protected', Token::_protected());
$this->assertPhpToken('public', Token::_public());
$this->assertPhpToken('require', Token::_require());
$this->assertPhpToken('require_once', Token::_requireOnce());
$this->assertPhpToken('return', Token::_return());
$this->assertPhpToken('static', Token::_static());
$this->assertPhpToken('switch', Token::_switch());
$this->assertPhpToken('throw', Token::_throw());
$this->assertPhpToken('trait', Token::_trait());
$this->assertPhpToken('try', Token::_try());
$this->assertPhpToken('unset', Token::_unset());
$this->assertPhpToken('use', Token::_use());
$this->assertPhpToken('var', Token::_var());
$this->assertPhpToken('while', Token::_while());
$this->assertPhpToken('and', Token::logicalAnd());
$this->assertPhpToken('or', Token::logicalOr());
$this->assertPhpToken('xor', Token::logicalXor());
$this->assertPhpToken('(array)', Token::arrayCast());
$this->assertPhpToken('(bool)', Token::booleanCast(), FALSE);
$this->assertPhpToken('(boolean)', Token::booleanCast());
$this->assertPhpToken('(real)', Token::doubleCast(), FALSE);
$this->assertPhpToken('(float)', Token::doubleCast(), FALSE);
$this->assertPhpToken('(double)', Token::doubleCast());
$this->assertPhpToken('(int)', Token::integerCast(), FALSE);
$this->assertPhpToken('(integer)', Token::integerCast());
$this->assertPhpToken('(object)', Token::objectCast());
$this->assertPhpToken('(string)', Token::stringCast());
$this->assertPhpToken('(unset)', Token::unsetCast());
$this->assertPhpToken('__halt_compiler', Token::haltCompiler());
$this->assertPhpToken('__CLASS__', Token::classConstant());
$this->assertPhpToken('__DIR__', Token::dirConstant());
$this->assertPhpToken('__FILE__', Token::fileConstant());
$this->assertPhpToken('__FUNCTION__', Token::functionConstant());
$this->assertPhpToken('__LINE__', Token::lineConstant());
$this->assertPhpToken('__METHOD__', Token::methodConstant());
$this->assertPhpToken('__NAMESPACE__', Token::namespaceConstant());
$this->assertPhpToken('__TRAIT__', Token::traitConstant());
$this->assertPhpToken('=>', Token::doubleArrow());
$this->assertPhpToken('->', Token::objectOperator());
$this->assertPhpToken('::', Token::doubleColon());
$this->assertPhpToken('&=', Token::bitwiseAndAssign());
$this->assertPhpToken('|=', Token::bitwiseOrAssign());
$this->assertPhpToken('^=', Token::bitwiseXorAssign());
$this->assertPhpToken('*=', Token::multiplyAssign());
$this->assertPhpToken('/=', Token::divideAssign());
$this->assertPhpToken('%=', Token::modulusAssign());
$this->assertPhpToken('+=', Token::addAssign());
$this->assertPhpToken('-=', Token::subtractAssign());
$this->assertPhpToken('.=', Token::concatAssign());
$this->assertPhpToken('===', Token::isIdentical());
$this->assertPhpToken('==', Token::isEqual());
//.........这里部分代码省略.........