本文整理汇总了PHP中Github\Client::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setOption方法的具体用法?PHP Client::setOption怎么用?PHP Client::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Github\Client
的用法示例。
在下文中一共展示了Client::setOption方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleResponse
public function handleResponse(UserResponseInterface $response, UserService $userService)
{
$fields = $response->getResponse();
$gitHubLogin = $fields['login'];
$accessToken = $response->getAccessToken();
$user = $userService->findByGitHubLogin($gitHubLogin);
if (null === $user) {
throw new UsernameNotFoundException();
}
$oAuthUser = new OAuthUser($user);
$oAuthUser->addRole('ROLE_GITHUB_USER');
$oAuthUser->setAccessToken($accessToken);
if (array_key_exists('name', $fields)) {
$gitHubName = $fields['name'];
$oAuthUser->setRealName($gitHubName);
} else {
$oAuthUser->setRealName($gitHubLogin);
}
$client = new Client();
$client->setOption('api_version', 'v3');
$client->authenticate($response->getAccessToken(), Client::AUTH_HTTP_TOKEN);
/* @var \Github\Api\CurrentUser $currentUserApi */
$currentUserApi = $client->api('current_user');
$emails = $currentUserApi->emails();
$allEMails = $emails->all();
$oAuthUser->setEmail($this->getPrimaryEmailAddress($allEMails));
return $oAuthUser;
}
示例2: createWithToken
/**
* Create a github client wrapper with automated token-based authentication.
*
* @param string $token The API token to authenticate with.
* @param string $owner The owner name of the github repository.
* @param string $repo The name of the github repository.
* @param string $apiUrl The base url to the github API if different from the main github site (i.e., GitHub Enterprise).
* @return self The github client wrapper, authenticated against the API.
*/
public static function createWithToken($token, $owner, $repo, $apiUrl = null)
{
$client = new Client();
if ($apiUrl !== null) {
$client->setOption('base_url', $apiUrl);
}
$client->authenticate($token, null, Client::AUTH_HTTP_TOKEN);
return new static($client, $owner, $repo);
}
示例3: buildGitHubClient
/**
* @return Client
*/
protected function buildGitHubClient()
{
$httpClient = new HttpClient(['base_url' => $this->config['base_url']]);
$client = new Client($httpClient);
if (false !== getenv('GITHUB_DEBUG')) {
$logPlugin = LogPlugin::getDebugPlugin();
$httpClient = $client->getHttpClient();
$httpClient->addSubscriber($logPlugin);
}
$client->setOption('base_url', $this->config['base_url']);
$this->url = rtrim($this->config['base_url'], '/');
$this->domain = rtrim($this->config['repo_domain_url'], '/');
return $client;
}