3 namespace Wallabag\CoreBundle\Helper
;
5 use Graby\Ring\Client\SafeCurlHandler
;
7 use GuzzleHttp\Cookie\CookieJar
;
8 use GuzzleHttp\Event\SubscriberInterface
;
11 * Builds and configures the Guzzle HTTP client.
13 class HttpClientFactory
15 /** @var \GuzzleHttp\Event\SubscriberInterface */
16 private $authenticatorSubscriber;
18 /** @var \GuzzleHttp\Cookie\CookieJar */
22 * HttpClientFactory constructor.
24 * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber
25 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar
27 public function __construct(SubscriberInterface
$authenticatorSubscriber, CookieJar
$cookieJar)
29 $this->authenticatorSubscriber
= $authenticatorSubscriber;
30 $this->cookieJar
= $cookieJar;
34 * @return \GuzzleHttp\Client
36 public function buildHttpClient()
38 // we clear the cookie to avoid websites who use cookies for analytics
39 $this->cookieJar
->clear();
40 // need to set the (shared) cookie jar
41 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar
]]);
42 $client->getEmitter()->attach($this->authenticatorSubscriber
);