]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
Added authentication for restricted access articles
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / HttpClientFactory.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Helper;
4
5 use Graby\Ring\Client\SafeCurlHandler;
6 use GuzzleHttp\Client;
7 use GuzzleHttp\Cookie\CookieJar;
8 use GuzzleHttp\Event\SubscriberInterface;
9
10 /**
11 * Builds and configures the Guzzle HTTP client.
12 */
13 class HttpClientFactory
14 {
15 /** @var \GuzzleHttp\Event\SubscriberInterface */
16 private $authenticatorSubscriber;
17
18 /** @var \GuzzleHttp\Cookie\CookieJar */
19 private $cookieJar;
20
21 /**
22 * HttpClientFactory constructor.
23 *
24 * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber
25 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar
26 */
27 public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar)
28 {
29 $this->authenticatorSubscriber = $authenticatorSubscriber;
30 $this->cookieJar = $cookieJar;
31 }
32
33 /**
34 * @return \GuzzleHttp\Client
35 */
36 public function buildHttpClient()
37 {
38 // need to set the (shared) cookie jar
39 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]);
40 $client->getEmitter()->attach($this->authenticatorSubscriber);
41
42 return $client;
43 }
44 }