Skip to content

Commit

Permalink
Merge pull request #3 from Aliance/curl_options
Browse files Browse the repository at this point in the history
Adding curl options for curl transport
  • Loading branch information
alxmsl committed Dec 12, 2015
2 parents ab2cb4c + b6f7442 commit 2118ff8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -31,6 +31,10 @@ Today it supports only curl transport type, but if future will other types. For

$Request->setTransport(Request::TRANSPORT_CURL);

Using curl transport, you can add any additional [curl options](http://php.net/manual/en/function.curl-setopt.php)

$Request->getTransport()->setOption(CURLOPT_FOLLOWLOCATION, true);

You can add url parameters for requests like a http://some.body/param1/value1/param2/value2

$Request->addUrlField('param1', 'value1')
Expand Down
24 changes: 23 additions & 1 deletion source/Http/CurlTransport.php
Expand Up @@ -33,6 +33,11 @@ final class CurlTransport implements TransportInterface {
*/
private $responseHeaders = array();

/**
* @var array additional curl options
*/
private $options = array();

/**
* Setter for request object
* @param Request $Request request object
Expand Down Expand Up @@ -82,7 +87,7 @@ public function makeHttpRequest() {
if (!$this->Request->isDefaultSslVersion()) {
$options[CURLOPT_SSLVERSION] = $this->Request->getSslVersion();
}
curl_setopt_array($Resource, $options);
curl_setopt_array($Resource, $this->getOptions() + $options);

$this->addHeaders($Resource, $this->Request->getHeaders());
$this->addPostData($Resource, $this->Request->getPostData());
Expand Down Expand Up @@ -118,6 +123,23 @@ public function makeHttpRequest() {
}
}

/**
* Get all manually setted curl options
* @return array assotiative array of curl options
*/
public function getOptions() {
return $this->options;
}

/**
* Add curl option
* @param int $option one of CURLOPT_* constant
* @param mixed $value curl option value
*/
public function setOption($option, $value) {
$this->options[$option] = $value;
}

/**
* Parsing response block for headers
* @param string $string response block
Expand Down
8 changes: 8 additions & 0 deletions source/Http/Request.php
Expand Up @@ -99,6 +99,7 @@ final class Request implements RequestInterface {
/**
* Send request data method
* @return string request execution result
* @throws TransportException in case of undefined Transport
*/
public function send() {
if (is_null($this->Transport)) {
Expand Down Expand Up @@ -169,6 +170,13 @@ public function getMethod() {
return $this->method;
}

/**
* @return TransportInterface transport implementation
*/
public function getTransport() {
return $this->Transport;
}

/**
* Transport object setter
* @param int $transportCode transport implementation code
Expand Down

0 comments on commit 2118ff8

Please sign in to comment.