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 */
21 private $restrictedAccess;
24 * HttpClientFactory constructor.
26 * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber
27 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar
28 * @param string $restrictedAccess this param is a kind of boolean. Values: 0 or 1
30 public function __construct(SubscriberInterface
$authenticatorSubscriber, CookieJar
$cookieJar, $restrictedAccess)
32 $this->authenticatorSubscriber
= $authenticatorSubscriber;
33 $this->cookieJar
= $cookieJar;
34 $this->restrictedAccess
= $restrictedAccess;
38 * @return \GuzzleHttp\Client|null
40 public function buildHttpClient()
42 if (0 === (int) $this->restrictedAccess
) {
46 // we clear the cookie to avoid websites who use cookies for analytics
47 $this->cookieJar
->clear();
48 // need to set the (shared) cookie jar
49 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar
]]);
50 $client->getEmitter()->attach($this->authenticatorSubscriber
);