From e2e522ddd65c34dcc0f9fef227e3da49c831b90f Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Tue, 6 Oct 2020 13:49:51 +1100 Subject: [PATCH] Fixes #87 and ensures that user agents are only added once per unique string. --- src/Connector/Client.php | 21 +++++++++++++++++++++ tests/Endpoints/ClientTest.php | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Connector/Client.php b/src/Connector/Client.php index 089f27bd..e9aa66f3 100644 --- a/src/Connector/Client.php +++ b/src/Connector/Client.php @@ -29,6 +29,11 @@ class Client implements ClientInterface */ protected $options = []; + /** + * @var array User agent strings to be concatenated and added to each request. + */ + protected $userAgent = []; + /** * Client constructor. * @@ -203,4 +208,20 @@ public function addOption($name, $value): void { $this->options = array_merge_recursive($this->options, [$name => $value]); } + + /** + * @inheritdoc + */ + public function setUserAgent($name): void + { + $this->userAgent[$name] = $name; + } + + /** + * @inheritdoc + */ + public function getUserAgent(): array + { + return $this->userAgent; + } } diff --git a/tests/Endpoints/ClientTest.php b/tests/Endpoints/ClientTest.php index 24b05614..8a32ef42 100644 --- a/tests/Endpoints/ClientTest.php +++ b/tests/Endpoints/ClientTest.php @@ -86,7 +86,6 @@ public function testModifyOptions() $client->addOption('headers', ['User-Agent' => 'AcquiaCli/4.20']); $client->addOption('headers', ['User-Agent' => 'ZCli/1.1.1']); $client->addOption('headers', ['User-Agent' => 'AaahCli/0.1']); - $client->addQuery('filter', 'name=@*2014*'); $client->addQuery('filter', 'type=@*true*'); $client->addQuery('limit', '1');