Skip to content

Commit

Permalink
Add headers in options (config) to client arguments; (#83)
Browse files Browse the repository at this point in the history
Fix: Content-Type in config.yml doesn't work #82
  • Loading branch information
Florian Preusner authored Dec 18, 2016
1 parent 88e1ed0 commit 7630ef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function createClientsNode()
->children()
->scalarNode('base_url')->defaultValue(null)->end()

// @deprecated
// @todo @deprecated
->arrayNode('headers')
->prototype('scalar')
->end()
Expand Down
20 changes: 14 additions & 6 deletions DependencyInjection/GuzzleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7630ef4

Please sign in to comment.