From 7630ef4eba3faee41ae5c94fc4e2bcc65935d123 Mon Sep 17 00:00:00 2001 From: Florian Preusner Date: Sun, 18 Dec 2016 22:46:04 +0100 Subject: [PATCH] Add headers in options (config) to client arguments; (#83) Fix: Content-Type in config.yml doesn't work #82 --- DependencyInjection/Configuration.php | 2 +- DependencyInjection/GuzzleExtension.php | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e4a42f4..adacf27 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -81,7 +81,7 @@ private function createClientsNode() ->children() ->scalarNode('base_url')->defaultValue(null)->end() - // @deprecated + // @todo @deprecated ->arrayNode('headers') ->prototype('scalar') ->end() diff --git a/DependencyInjection/GuzzleExtension.php b/DependencyInjection/GuzzleExtension.php index 2e4d454..66a07f4 100644 --- a/DependencyInjection/GuzzleExtension.php +++ b/DependencyInjection/GuzzleExtension.php @@ -53,23 +53,31 @@ public function load(array $configs, ContainerBuilder $container) 'handler' => $this->createHandler($container, $name, $options) ]; + // header hotfix/workaround #77 + // @todo @deprecated + if (isset($options['headers'])) { + $argument['headers'] = $this->cleanUpHeaders($options['headers']); + } + // if present, add default options to the constructor argument for the Guzzle client if (array_key_exists('options', $options) && is_array($options['options'])) { + foreach ($options['options'] as $key => $value) { + if ($value === null || (is_array($value) && count($value) === 0)) { continue; } + // @todo: cleanup + if ($key === 'headers') { + $argument[$key] = $this->cleanUpHeaders($value); + continue; + } + $argument[$key] = $value; } } - // header hotfix/workaround #77 - // @deprecated - if (isset($options['headers'])) { - $argument['headers'] = $this->cleanUpHeaders($options['headers']); - } - $client = new Definition('%guzzle.http_client.class%'); $client->addArgument($argument);