本文整理汇总了PHP中Github\Client::getHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getHttpClient方法的具体用法?PHP Client::getHttpClient怎么用?PHP Client::getHttpClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Github\Client
的用法示例。
在下文中一共展示了Client::getHttpClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
public function build($username, $repository)
{
$this->repository = new Repository($username, $repository);
// repository data
$data = $this->client->api('repo')->show($this->repository->username, $this->repository->repository);
$this->repository->size = $data['size'];
$this->repository->stargazersCount = $data['stargazers_count'];
$this->repository->forks = $data['forks'];
$this->repository->openIssues = $data['open_issues'];
$this->repository->subscribersCount = $data['subscribers_count'];
// repository commit activity
do {
$activity = $this->client->api('repo')->activity($this->repository->username, $this->repository->repository);
$responseStatusCode = $this->client->getHttpClient()->getLastResponse()->getStatusCode();
if ($responseStatusCode != 200) {
sleep(3);
} else {
break;
}
} while (true);
$commitsLastYear = array_map(function (array $weekCommits) {
return $weekCommits['total'];
}, $activity);
$this->repository->commitsCount = array_sum($commitsLastYear);
$this->repository->commitsLastMonthCount = array_sum(array_slice($commitsLastYear, -4));
$this->repository->avgCommitsPerWeek = count($commitsLastYear) > 0 ? floor(array_sum($commitsLastYear) / count($commitsLastYear)) : 0;
// repository contributors
$paginator = new ResultPager($this->client);
$contributors = $paginator->fetchAll($this->client->api('repo'), 'contributors', [$this->repository->username, $this->repository->repository, true]);
$this->repository->contributorsCount = count($contributors);
// user data
$user = $this->client->api('user')->show($this->repository->username);
$this->repository->userPublicRepos = $user['public_repos'];
return $this;
}
示例2: setHttpClient
/**
* @param Client $githubClient
* @return GithubRepository
*/
public function setHttpClient(Client $githubClient)
{
$this->githubClient = $githubClient;
// see https://developer.github.com/changes/2015-04-17-preview-repository-redirects/
$this->githubClient->getHttpClient()->setHeaders(array('Accept' => 'application/vnd.github.quicksilver-preview+json'));
return $this;
}
示例3: updateVersionsHistory
public function updateVersionsHistory(Bundle $bundle)
{
// no composer file
if (null === ($composerName = $bundle->getComposerName())) {
return false;
}
// query packagist json
$packagistArray = $this->github->getHttpClient()->get($composerName, array(), array('url' => 'http://packagist.org/packages/:path.json'));
// if json not encoded
if (!is_array($packagistArray) || !isset($packagistArray['package'])) {
return false;
}
$versionsHistory = array();
$versionsArray = $packagistArray['package']['versions'];
foreach ($versionsArray as $version => $value) {
// Skip `dev` packages, add only `dev-master`
if (0 === strpos($version, 'dev-') && 'dev-master' != $version) {
continue;
}
foreach (array('symfony/framework-bundle', 'symfony/symfony') as $requirement) {
if (isset($value['require'][$requirement])) {
$versionsHistory['symfony'][$version] = $value['require'][$requirement];
// array('master' => '>=2.0,<2.2-dev')
}
}
// store all bundle dependencies
$versionsHistory['dependencies'][$version] = array('name' => $value['name'], 'extra' => isset($value['extra']) ? $value['require-dev'] : '', 'require' => $value['require'], 'require-dev' => isset($value['require-dev']) ? $value['require-dev'] : '', 'suggest' => isset($value['suggest']) ? $value['suggest'] : '');
}
if (!empty($versionsHistory)) {
$bundle->setVersionsHistory($versionsHistory);
}
return true;
}
示例4: getContents
/**
* Temporary workaround of the GitHub client bug
*
* @param string $sha
* @return string
*/
protected function getContents($sha)
{
$path = 'repos/' . rawurlencode($this->user) . '/' . rawurlencode($this->repo) . '/git/blobs/' . rawurlencode($sha);
$response = $this->client->getHttpClient()->get($path);
$contents = $response->getBody(true);
return $contents;
}
示例5: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['github'] = $app->share(function () {
$client = new Client(new CachedHttpClient(['cache_dir' => __DIR__ . '/../../../app/cache/github-api-cache']));
return new GithubAdapter($client->getHttpClient());
});
}
示例6: get
/**
* {@inheritdoc}
*/
protected function get($key)
{
if ($this->has($key)) {
$result = $this->client->getHttpClient()->get($this->pagination[$key]);
$this->postFetch();
return ResponseMediator::getContent($result);
}
}
示例7: updateRemoteStatus
/**
* Update webhooks for repo
*
* @param $repo
* @param $secret
*/
private function updateRemoteStatus($repo, $secret)
{
foreach (['issues', 'issue_comment'] as $event) {
$action = $repo->isUsed() ? 'subscribe' : 'unsubscribe';
$topic = 'https://github.com/' . $repo->getFullname() . '/events/' . $event;
$this->client->getHttpClient()->post('/hub', ['hub.mode' => $action, 'hub.topic' => $topic, 'hub.callback' => UrlHelper::getHost() . '/github/fromissue', 'hub.secret' => $secret]);
}
}
示例8: logHttp
/**
* Debug HTTP interactions
*
* @param Client $client
* @param OutputInterface $output
*/
protected function logHttp(Client $client, OutputInterface $output)
{
$guzzle = $client->getHttpClient();
if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
$logger = function ($message) use($output) {
$finfo = new \finfo(FILEINFO_MIME);
$msg = substr($finfo->buffer($message), 0, 4) == 'text' ? $message : '(binary string)';
$output->writeln('<info>Guzzle</info> ' . $msg);
};
$logAdapter = new ClosureLogAdapter($logger);
$logPlugin = new LogPlugin($logAdapter, MessageFormatter::DEBUG_FORMAT);
$guzzle->addSubscriber($logPlugin);
}
}
示例9: 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;
}
示例10: it_returns_Issue_objects_on_getIssues
public function it_returns_Issue_objects_on_getIssues(Client $client, Issue $api, HttpClient $http, Response $response)
{
$client->issue()->willReturn($api);
$client->getHttpClient()->willReturn($http);
$api->getPerPage()->willReturn(5);
$api->setPerPage(Argument::any())->willReturn();
$http->getLastResponse()->willReturn($response);
$response->getHeader('Link')->willReturn(null);
$api->all('foo', 'bar', ['state' => 'open'])->willReturn([['number' => 1], ['number' => 5]]);
$result = $this->getIssues();
$result->shouldBeArray();
$result->shouldHaveCount(2);
$result[0]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue');
$result[0]->getId()->shouldBe(1);
$result[1]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue');
$result[1]->getId()->shouldBe(5);
}
示例11: testInstanciateWithHttpClient
public function testInstanciateWithHttpClient()
{
$httpClient = $this->getHttpClientMock();
$client = new Client($httpClient);
$this->assertEquals($httpClient, $client->getHttpClient());
}
示例12: shouldSetHeadersLaizly
/**
* @test
*/
public function shouldSetHeadersLaizly()
{
$client = new Client();
$client->setHeaders(array('header1', 'header2'));
$this->assertInstanceOf('Github\\HttpClient\\HttpClientInterface', $client->getHttpClient());
}
示例13: postGistComment
/**
* @param $gistId
* @param $comment
* @return array
*/
public function postGistComment($gistId, $comment)
{
$this->github->authenticate(Auth::user()->token, GitHubClient::AUTH_HTTP_TOKEN);
$response = $this->github->getHttpClient()->post("gists/{$gistId}/comments", json_encode(['body' => $comment]));
return ResponseMediator::getContent($response);
}
示例14: getRawActivities
private function getRawActivities($limit = 5)
{
$response = $this->client->getHttpClient()->get("users/{$this->user}/events");
$activities = ResponseMediator::getContent($response);
return array_slice($activities, 0, $limit);
}
示例15: shouldPassHttpClientInterfaceToConstructor
/**
* @test
*/
public function shouldPassHttpClientInterfaceToConstructor()
{
$client = new Client($this->getHttpClientMock());
$this->assertInstanceOf('Github\\HttpClient\\HttpClientInterface', $client->getHttpClient());
}