summaryrefslogtreecommitdiffstats
path: root/lib/Client.php
diff options
context:
space:
mode:
authorAlain Tiemblo <alain.tiemblo@blablacar.com>2016-10-11 08:22:27 +0200
committerAlain Tiemblo <alain.tiemblo@blablacar.com>2016-10-11 08:22:27 +0200
commit151b07c418952a64c9f58c47ba14a25e1f3d2060 (patch)
treed1191f94d1acf4165738c1f6d8c9a663f9bbe831 /lib/Client.php
parent9ea03457478549eacd191d6476ae78a6b868af57 (diff)
downloadphp-http-client-151b07c418952a64c9f58c47ba14a25e1f3d2060.zip
php-http-client-151b07c418952a64c9f58c47ba14a25e1f3d2060.tar.gz
php-http-client-151b07c418952a64c9f58c47ba14a25e1f3d2060.tar.bz2
Added curlOptions property to customize curl instance
Diffstat (limited to 'lib/Client.php')
-rw-r--r--lib/Client.php34
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/Client.php b/lib/Client.php
index d5f997b..1e77470 100644
--- a/lib/Client.php
+++ b/lib/Client.php
@@ -29,26 +29,30 @@ class Client
/** @var array */
protected $path;
/** @var array */
+ protected $curlOptions;
+ /** @var array */
private $methods;
/**
* Initialize the client
*
- * @param string $host the base url (e.g. https://api.sendgrid.com)
- * @param array $headers global request headers
- * @param string $version api version (configurable)
- * @param array $path holds the segments of the url path
+ * @param string $host the base url (e.g. https://api.sendgrid.com)
+ * @param array $headers global request headers
+ * @param string $version api version (configurable)
+ * @param array $path holds the segments of the url path
+ * @param array $curlOptions extra options to set during curl initialization
*/
- public function __construct($host, $headers = null, $version = null, $path = null)
+ public function __construct($host, $headers = null, $version = null, $path = null, $curlOptions = null)
{
$this->host = $host;
$this->headers = $headers ?: [];
$this->version = $version;
$this->path = $path ?: [];
+ $this->curlOptions = $curlOptions ?: [];
// These are the supported HTTP verbs
$this->methods = ['delete', 'get', 'patch', 'post', 'put'];
}
-
+
/**
* @return string
*/
@@ -56,7 +60,7 @@ class Client
{
return $this->host;
}
-
+
/**
* @return array
*/
@@ -64,7 +68,7 @@ class Client
{
return $this->headers;
}
-
+
/**
* @return string|null
*/
@@ -72,7 +76,7 @@ class Client
{
return $this->version;
}
-
+
/**
* @return array
*/
@@ -82,6 +86,14 @@ class Client
}
/**
+ * @return array
+ */
+ public function getCurlOptions()
+ {
+ return $this->curlOptions;
+ }
+
+ /**
* Make a new Client object
*
* @param string $name name of the url segment
@@ -129,12 +141,12 @@ class Client
{
$curl = curl_init($url);
- curl_setopt_array($curl, [
+ curl_setopt_array($curl, array_merge([
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => 1,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_SSL_VERIFYPEER => false,
- ]);
+ ], $this->curlOptions));
if (isset($headers)) {
$this->headers = array_merge($this->headers, $headers);