From 5b914b0422e08c4b4859050026823af677c97727 Mon Sep 17 00:00:00 2001 From: Bertrand Dunogier Date: Sat, 14 Jan 2017 16:42:03 +0100 Subject: Improved Guzzle subscribers extensibility Allows 3rd parties to register new guzzle subscribers by adding extra calls to the http_client_factory service. --- .../CoreBundle/Helper/HttpClientFactory.php | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') 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; */ class HttpClientFactory { - /** @var \GuzzleHttp\Event\SubscriberInterface */ - private $authenticatorSubscriber; + /** @var [\GuzzleHttp\Event\SubscriberInterface] */ + private $subscribers = []; /** @var \GuzzleHttp\Cookie\CookieJar */ private $cookieJar; @@ -25,14 +25,12 @@ class HttpClientFactory /** * HttpClientFactory constructor. * - * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber - * @param \GuzzleHttp\Cookie\CookieJar $cookieJar - * @param string $restrictedAccess this param is a kind of boolean. Values: 0 or 1 + * @param \GuzzleHttp\Cookie\CookieJar $cookieJar + * @param string $restrictedAccess This param is a kind of boolean. Values: 0 or 1 * @param LoggerInterface $logger */ - public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger) + public function __construct(CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger) { - $this->authenticatorSubscriber = $authenticatorSubscriber; $this->cookieJar = $cookieJar; $this->restrictedAccess = $restrictedAccess; $this->logger = $logger; @@ -53,8 +51,20 @@ class HttpClientFactory $this->cookieJar->clear(); // need to set the (shared) cookie jar $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]); - $client->getEmitter()->attach($this->authenticatorSubscriber); + foreach ($this->subscribers as $subscriber) { + $client->getEmitter()->attach($subscriber); + } return $client; } + + /** + * Adds a subscriber to the HTTP client. + * + * @param SubscriberInterface $subscriber + */ + public function addSubscriber(SubscriberInterface $subscriber) + { + $this->subscribers[] = $subscriber; + } } -- cgit v1.2.3 From d047530dc07ceb5a109cd0caa95055d8b071dbd4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 11:17:09 +0200 Subject: CS --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 09439dff..11ef26d8 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -27,7 +27,7 @@ class HttpClientFactory * * @param \GuzzleHttp\Cookie\CookieJar $cookieJar * @param string $restrictedAccess This param is a kind of boolean. Values: 0 or 1 - * @param LoggerInterface $logger + * @param LoggerInterface $logger */ public function __construct(CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger) { -- cgit v1.2.3 From 94b232bbb8de4699911a6446a1a96f75370cab50 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 22:25:18 +0200 Subject: Skip auth when no credentials are found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we can’t find a credential for the current host, even if it required login, we won’t add them and website will be fetched without any login. --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 11ef26d8..43f5b119 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -51,6 +51,7 @@ class HttpClientFactory $this->cookieJar->clear(); // need to set the (shared) cookie jar $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]); + foreach ($this->subscribers as $subscriber) { $client->getEmitter()->attach($subscriber); } -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 43f5b119..4602a684 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -41,7 +41,7 @@ class HttpClientFactory */ public function buildHttpClient() { - $this->logger->log('debug', 'Restricted access config enabled?', array('enabled' => (int) $this->restrictedAccess)); + $this->logger->log('debug', 'Restricted access config enabled?', ['enabled' => (int) $this->restrictedAccess]); if (0 === (int) $this->restrictedAccess) { return; -- cgit v1.2.3