Skip to content

Commit 644c20d

Browse files
committed
Merge pull request #47 from cmfcmf/allow-curl-options
Allow to set additional Curl options.
2 parents a722730 + 25ec0c4 commit 644c20d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Cmfcmf/OpenWeatherMap/Fetcher/CurlFetcher.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,33 @@
2424
*/
2525
class CurlFetcher implements FetcherInterface
2626
{
27+
/**
28+
* @var array The Curl options to use.
29+
*/
30+
private $curlOptions;
31+
32+
/**
33+
* Create a new CurlFetcher instance.
34+
*
35+
* @param array $curlOptions The Curl options to use. See http://php.net/manual/de/function.curl-setopt.php
36+
* for a list of available options.
37+
*/
38+
public function __construct($curlOptions = array())
39+
{
40+
$this->curlOptions = $curlOptions;
41+
}
42+
2743
/**
2844
* {@inheritdoc}
2945
*/
3046
public function fetch($url)
3147
{
3248
$ch = curl_init($url);
33-
$timeout = 5;
3449
curl_setopt($ch, CURLOPT_URL, $url);
3550
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
36-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
51+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
52+
curl_setopt_array($ch, $this->curlOptions);
53+
3754
$content = curl_exec($ch);
3855
curl_close($ch);
3956

0 commit comments

Comments
 (0)