Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 2ed4afa

Browse files
committed
Adding helper method that is called from send
This allows subclasses to change the behavior around adapter interaction
1 parent babd671 commit 2ed4afa

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

src/Client.php

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -821,23 +821,10 @@ public function send(Request $request = null)
821821
throw new Client\Exception\RuntimeException('Adapter does not support streaming');
822822
}
823823

824-
// Open the connection, send the request and read the response
825-
$this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);
824+
// calling protected method to allow extending classes
825+
// to wrap the interaction with the adapter
826+
$response = $this->doRequest($uri, $method, $secure, $headers, $body);
826827

827-
if($this->config['outputstream']) {
828-
if($this->adapter instanceof Client\Adapter\Stream) {
829-
$stream = $this->openTempStream();
830-
$this->adapter->setOutputStream($stream);
831-
} else {
832-
throw new Exception\RuntimeException('Adapter does not support streaming');
833-
}
834-
}
835-
836-
// HTTP connection
837-
$this->lastRawRequest = $this->adapter->write($method,
838-
$uri, $this->config['httpversion'], $headers, $body);
839-
840-
$response = $this->adapter->read();
841828
if (! $response) {
842829
throw new Exception\RuntimeException('Unable to read response, or response is empty');
843830
}
@@ -1274,6 +1261,39 @@ protected function flattenParametersArray($parray, $prefix = null)
12741261
return $parameters;
12751262
}
12761263

1264+
/**
1265+
* Separating this from send method allows subclasses to wrap
1266+
* the interaction with the adapter
1267+
*
1268+
* @param Http $uri
1269+
* @param string $secure
1270+
* @param string $method
1271+
* @param array $headers
1272+
* @param string $body
1273+
* @return string the raw response
1274+
* @throws Exception\RuntimeException
1275+
*/
1276+
protected function doRequest(Http $uri, $method, $secure = false, $headers = array(), $body = '')
1277+
{
1278+
// Open the connection, send the request and read the response
1279+
$this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);
1280+
1281+
if($this->config['outputstream']) {
1282+
if($this->adapter instanceof Client\Adapter\Stream) {
1283+
$stream = $this->openTempStream();
1284+
$this->adapter->setOutputStream($stream);
1285+
} else {
1286+
throw new Exception\RuntimeException('Adapter does not support streaming');
1287+
}
1288+
}
1289+
1290+
// HTTP connection
1291+
$this->lastRawRequest = $this->adapter->write($method,
1292+
$uri, $this->config['httpversion'], $headers, $body);
1293+
1294+
return $this->adapter->read();
1295+
}
1296+
12771297
/**
12781298
* Returns length of binary string in bytes
12791299
*

0 commit comments

Comments
 (0)