diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php new file mode 100644 index 00000000..3e1d1ed5 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | |||
@@ -0,0 +1,44 @@ | |||
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 | } | ||