aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBertrand Dunogier <bertrand.dunogier@ez.no>2017-01-14 16:42:03 +0100
committerBertrand Dunogier <bertrand.dunogier@ez.no>2017-05-04 21:44:34 +0200
commit5b914b0422e08c4b4859050026823af677c97727 (patch)
tree32c16dc4067f952acba80221916cae5feb99acc9
parentcebed9c01f20d47cb60259f0c002ea57a80da4d0 (diff)
downloadwallabag-5b914b0422e08c4b4859050026823af677c97727.tar.gz
wallabag-5b914b0422e08c4b4859050026823af677c97727.tar.zst
wallabag-5b914b0422e08c4b4859050026823af677c97727.zip
Improved Guzzle subscribers extensibility
Allows 3rd parties to register new guzzle subscribers by adding extra calls to the http_client_factory service.
-rw-r--r--src/Wallabag/CoreBundle/Helper/HttpClientFactory.php26
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml3
2 files changed, 20 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
index 1ac8feb1..09439dff 100644
--- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
+++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
@@ -13,8 +13,8 @@ use Psr\Log\LoggerInterface;
13 */ 13 */
14class HttpClientFactory 14class HttpClientFactory
15{ 15{
16 /** @var \GuzzleHttp\Event\SubscriberInterface */ 16 /** @var [\GuzzleHttp\Event\SubscriberInterface] */
17 private $authenticatorSubscriber; 17 private $subscribers = [];
18 18
19 /** @var \GuzzleHttp\Cookie\CookieJar */ 19 /** @var \GuzzleHttp\Cookie\CookieJar */
20 private $cookieJar; 20 private $cookieJar;
@@ -25,14 +25,12 @@ class HttpClientFactory
25 /** 25 /**
26 * HttpClientFactory constructor. 26 * HttpClientFactory constructor.
27 * 27 *
28 * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber 28 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar
29 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar 29 * @param string $restrictedAccess This param is a kind of boolean. Values: 0 or 1
30 * @param string $restrictedAccess this param is a kind of boolean. Values: 0 or 1
31 * @param LoggerInterface $logger 30 * @param LoggerInterface $logger
32 */ 31 */
33 public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger) 32 public function __construct(CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger)
34 { 33 {
35 $this->authenticatorSubscriber = $authenticatorSubscriber;
36 $this->cookieJar = $cookieJar; 34 $this->cookieJar = $cookieJar;
37 $this->restrictedAccess = $restrictedAccess; 35 $this->restrictedAccess = $restrictedAccess;
38 $this->logger = $logger; 36 $this->logger = $logger;
@@ -53,8 +51,20 @@ class HttpClientFactory
53 $this->cookieJar->clear(); 51 $this->cookieJar->clear();
54 // need to set the (shared) cookie jar 52 // need to set the (shared) cookie jar
55 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]); 53 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]);
56 $client->getEmitter()->attach($this->authenticatorSubscriber); 54 foreach ($this->subscribers as $subscriber) {
55 $client->getEmitter()->attach($subscriber);
56 }
57 57
58 return $client; 58 return $client;
59 } 59 }
60
61 /**
62 * Adds a subscriber to the HTTP client.
63 *
64 * @param SubscriberInterface $subscriber
65 */
66 public function addSubscriber(SubscriberInterface $subscriber)
67 {
68 $this->subscribers[] = $subscriber;
69 }
60} 70}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index bccb2e19..68f900a1 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -71,10 +71,11 @@ services:
71 wallabag_core.guzzle.http_client_factory: 71 wallabag_core.guzzle.http_client_factory:
72 class: Wallabag\CoreBundle\Helper\HttpClientFactory 72 class: Wallabag\CoreBundle\Helper\HttpClientFactory
73 arguments: 73 arguments:
74 - "@bd_guzzle_site_authenticator.authenticator_subscriber"
75 - "@wallabag_core.guzzle.cookie_jar" 74 - "@wallabag_core.guzzle.cookie_jar"
76 - '@=service(''craue_config'').get(''restricted_access'')' 75 - '@=service(''craue_config'').get(''restricted_access'')'
77 - '@logger' 76 - '@logger'
77 calls:
78 - ["addSubscriber", ["@bd_guzzle_site_authenticator.authenticator_subscriber"]]
78 79
79 wallabag_core.guzzle.cookie_jar: 80 wallabag_core.guzzle.cookie_jar:
80 class: GuzzleHttp\Cookie\FileCookieJar 81 class: GuzzleHttp\Cookie\FileCookieJar