33
44### Configure the http client
55
6- Wanna change, let's say, the http client User Agent?
6+ Wanna change, let's say, the http client User Agent? You need to create a Plugin that modifies the
7+ request. Read more about [ HTTPlug plugins here] ( http://docs.php-http.org/en/latest/plugins/introduction.html#how-it-works ) .
78
89``` php
9- $client->getHttpClient()->setOption('user_agent', 'My new User Agent');
10- ```
11-
12- See all available options in ` Github/HttpClient/HttpClient.php `
13-
14- ### Guzzle events
15-
16- If you need to perform any special action on request/response use guzzle events:
17-
18- ``` php
19- use Guzzle\Common\Event;
20- use Github\HttpClient\Message\ResponseMediator;
10+ use Http\Client\Common\Plugin;
11+ use Psr\Http\Message\RequestInterface;
2112
22- $client->getHttpClient()->addListener('request.success', function(Event $event) {
23- $remaining = ResponseMediator::getApiLimit($event['response']);
13+ class CustomUserAgentPlugin implements Plugin
14+ {
15+ /**
16+ * {@inheritdoc}
17+ */
18+ public function handleRequest(RequestInterface $request, callable $next, callable $first)
19+ {
20+ $request->withHeader('user-agent', 'Foobar');
2421
25- var_dump($remaining);
26- });
22+ return $next($request);
23+ }
24+ }
2725
28- $client->user()->show('cursedcoder' );
26+ $githubClient->addPlugin(new CustomUserAgentPlugin() );
2927```
3028
31- see list of events http://guzzle3.readthedocs.org/http-client/request.html#plugins-and-events
32-
3329### Inject a new http client instance
3430
35- ` php-github-api ` provides a curl-based implementation of a http client.
36- If you want to use your own http client implementation, inject it to the ` Github\Client ` instance:
31+ ` php-github-api ` relies on ` php-http/discovery ` to find an installed http client. You may specify a HTTP client
32+ yourself by calling ` \Github\Client::setHttpClient ` . A HTTP client must implement ` Http\Client\HttpClient ` . A list of
33+ community provided clients is found here: https://packagist.org/providers/php-http/client-implementation
3734
3835``` php
3936use Github\HttpClient\HttpClient;
@@ -54,7 +51,7 @@ You can now inject your http client through `Github\Client#setHttpClient()` meth
5451
5552``` php
5653$client = new Github\Client();
57- $client->setHttpClient(new MyHttpClient ());
54+ $client->setHttpClient(new Http\Adapter\Guzzle6\Client ());
5855```
5956
6057### Run Test Suite
0 commit comments