From 0900cb3050dbbc47d9348ccf4c8bcb343378ac45 Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Mon, 10 May 2021 12:52:00 +0100 Subject: [PATCH] feat: support injecting handlerstack through di --- Resources/config/services.yml | 5 +++++ Service/ApiFactory.php | 12 +++++++++--- composer.json | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 0753eb8..8e60d37 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -7,6 +7,10 @@ services: - 'api' - 1800 + bookboon.handlerstack: + class: GuzzleHttp\HandlerStack + factory: ['GuzzleHttp\HandlerStack', 'create'] + Bookboon\Api\Bookboon: public: true lazy: true @@ -15,5 +19,6 @@ services: - '@Bookboon\ApiBundle\Helper\ConfigurationHolder' - '@bookboon.cache' - '@monolog.logger.api' + - '@bookboon.handlerstack' tags: - { name: monolog.logger, channel: api } diff --git a/Service/ApiFactory.php b/Service/ApiFactory.php index d21182e..737ce5e 100644 --- a/Service/ApiFactory.php +++ b/Service/ApiFactory.php @@ -7,6 +7,7 @@ use Bookboon\Api\Client\Oauth\OauthGrants; use Bookboon\Api\Client\OauthClient; use Bookboon\ApiBundle\Helper\ConfigurationHolder; +use GuzzleHttp\HandlerStack; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; @@ -19,8 +20,12 @@ class ApiFactory * @return Bookboon * @throws \Bookboon\Api\Exception\UsageException */ - public static function create(ConfigurationHolder $config, CacheInterface $cache, LoggerInterface $logger) - { + public static function create( + ConfigurationHolder $config, + CacheInterface $cache, + LoggerInterface $logger, + HandlerStack $stack + ) { $bookboon = new Bookboon( new OauthClient( $config->getId(), @@ -32,7 +37,8 @@ public static function create(ConfigurationHolder $config, CacheInterface $cache null, $config->getOverrideAuthUri(), $config->getOverrideApiUri(), - $logger + $logger, + ['handler' => $stack] ) ); diff --git a/composer.json b/composer.json index f249852..b3369af 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/dependency-injection": "^4.0|^5.0", "symfony/config": "^4.0|^5.0", "symfony/cache": "^4.0|^5.0", - "bookboon/api": "~4.0" + "bookboon/api": "~4.12" }, "autoload": { "psr-4": {