Skip to content

Loading…

modified curl to support options #590

Merged
merged 3 commits into from

3 participants

@fellars

now able to add options to curl via the config array or via function parameter

@nateabele
Union of RAD member

Looks good to me. @gwoo?

@gwoo gwoo commented on an outdated diff
net/socket/Curl.php
@@ -59,6 +60,9 @@ public function open(array $options = array()) {
parent::open($options);
$config = $this->_config;
+ if (!empty($config['options'])){
@gwoo Union of RAD member
gwoo added a note

This should probably happen after the schema and host are checked.

@nateabele Union of RAD member

Oh yeah, also, coding standards.

@fellars
fellars added a note

@gwoo - moved to below
@nateabele - sorry, I went through coding standards and not sure what I'm doing wrong there. I fixed the tab vs. 4-spaces issue (I think)

@nateabele Union of RAD member

There should be a space between ) and {. Looks good otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gwoo gwoo merged commit ff59bc6 into UnionOfRAD:dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 19, 2012
  1. @fellars

    modified curl to support options

    fellars committed
Commits on Jul 20, 2012
  1. @fellars
  2. @fellars

    fixed spacing

    fellars committed
Showing with 17 additions and 0 deletions.
  1. +4 −0 net/socket/Curl.php
  2. +13 −0 tests/cases/net/socket/CurlTest.php
View
4 net/socket/Curl.php
@@ -50,6 +50,7 @@ public function __construct(array $config = array()) {
* Opens a curl connection and initializes the internal resource handle.
*
* @param array $options update the config settings
+ * if $options['options'] exists, will be passed to $this->set()
* @return mixed Returns `false` if the socket configuration does not contain the
* `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
* resource stream.
@@ -62,6 +63,9 @@ public function open(array $options = array()) {
if (empty($config['scheme']) || empty($config['host'])) {
return false;
}
+ if (!empty($config['options'])) {
+ $this->set($config['options']);
+ }
$url = "{$config['scheme']}://{$config['host']}";
$this->_resource = curl_init($url);
View
13 tests/cases/net/socket/CurlTest.php
@@ -140,6 +140,19 @@ public function testSettingOfOptions() {
$this->assertEqual('Changed Dummy Value', $stream->options['DummyFlag']);
}
+ public function testSettingOfOptionsInConfig() {
+ $this->_testConfig['options'] = array('DummyFlag'=> 'Dummy Value');
+ $stream = new Curl($this->_testConfig);
+ $stream->open();
+ $this->assertEqual('Dummy Value', $stream->options['DummyFlag']);
+ }
+
+ public function testSettingOfOptionsInOpen() {
+ $stream = new Curl($this->_testConfig);
+ $stream->open(array('options'=>array('DummyFlag'=> 'Dummy Value')));
+ $this->assertEqual('Dummy Value', $stream->options['DummyFlag']);
+ }
+
public function testSendPostThenGet() {
$postConfig = array('method' => 'POST', 'body' => '{"body"}');
$stream = new Curl($this->_testConfig);
Something went wrong with that request. Please try again.