Skip to content

Commit

Permalink
Allow URI of web service to be set on the Guzzle implementations of \…
Browse files Browse the repository at this point in the history
…Josser\Client\Transport\TransportInterface as alternative of relying on the base_uri of the Guzzle client.
  • Loading branch information
dennisverspuij authored and alanbem committed Jun 1, 2017
1 parent cf60168 commit ba72670
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Josser/Client/Transport/Guzzle5Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ class Guzzle5Transport implements TransportInterface
*/
private $guzzle;

/**
* URI of the web service, or null to use the base_uri of the Guzzle http client.
*
* @var string|null
*/
private $uri;

/**
* @param Client $guzzle
* @param string|null $uri URL of the web service, or null to use the base_uri of $guzzle
*/
public function __construct(Client $guzzle)
public function __construct(Client $guzzle, $uri = null)
{
$this->guzzle = $guzzle;
$this->uri = $uri;
}

/**
Expand All @@ -54,7 +63,7 @@ public function getGuzzle()
public function send($data)
{
try {
$response = $this->guzzle->post(null, [
$response = $this->guzzle->post($this->uri, [
'body' => $data,
'headers' => [
'Content-Type' => 'application/json',
Expand Down
13 changes: 11 additions & 2 deletions src/Josser/Client/Transport/Guzzle6Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ class Guzzle6Transport implements TransportInterface
*/
private $guzzle;

/**
* URI of the web service, or null to use the base_uri of the Guzzle http client.
*
* @var string|null
*/
private $uri;

/**
* @param Client $guzzle
* @param string|null $uri URL of the web service, or null to use the base_uri of $guzzle
*/
public function __construct(Client $guzzle)
public function __construct(Client $guzzle, $uri = null)
{
$this->guzzle = $guzzle;
$this->uri = $uri;
}

/**
Expand All @@ -54,7 +63,7 @@ public function getGuzzle()
public function send($data)
{
try {
$response = $this->guzzle->request('POST', null, [
$response = $this->guzzle->request('POST', $this->uri, [
'body' => $data,
'headers' => [
'Content-Type' => 'application/json',
Expand Down

0 comments on commit ba72670

Please sign in to comment.