Skip to content

Commit a1112fb

Browse files
committed
Add transient (one-time) options that only apply to the next curl service call; fixes #53
1 parent 6c237e9 commit a1112fb

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ abstract class AbstractWebDriver
4747
*/
4848
private $curlService;
4949

50+
/**
51+
* Transient options
52+
*
53+
* @var array
54+
*/
55+
private $transientOptions;
56+
5057
/**
5158
* Return array of supported method names and corresponding HTTP request methods
5259
*
@@ -114,6 +121,16 @@ public function getCurlService()
114121
return $this->curlService ?: ServiceFactory::getInstance()->getService('service.curl');
115122
}
116123

124+
/**
125+
* Set transient options
126+
*
127+
* @param array $transientOptions
128+
*/
129+
public function setTransientOptions($transientOptions)
130+
{
131+
$this->transientOptions = is_array($transientOptions) ? $transientOptions : array();
132+
}
133+
117134
/**
118135
* Curl request to webdriver server.
119136
*
@@ -147,7 +164,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
147164
$url .= '/' . $parameters;
148165
}
149166

150-
list($rawResult, $info) = $this->curlService->execute($requestMethod, $url, $parameters, $extraOptions);
167+
list($rawResult, $info) = $this->curlService->execute($requestMethod, $url, $parameters, array_merge($extraOptions, $this->transientOptions));
168+
169+
$this->transientOptions = array();
151170

152171
$httpCode = $info['http_code'];
153172

lib/WebDriver/SauceLabs/SauceRest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class SauceRest
4848
*/
4949
private $curlService;
5050

51+
/**
52+
* Transient options
53+
*
54+
* @var array
55+
*/
56+
private $transientOptions;
57+
5158
/**
5259
* Constructor
5360
*
@@ -80,20 +87,31 @@ public function getCurlService()
8087
return $this->curlService ?: ServiceFactory::getInstance()->getService('service.curl');
8188
}
8289

90+
/**
91+
* Set transient options
92+
*
93+
* @param array $transientOptions
94+
*/
95+
public function setTransientOptions($transientOptions)
96+
{
97+
$this->transientOptions = is_array($transientOptions) ? $transientOptions : array();
98+
}
99+
83100
/**
84101
* Execute Sauce Labs REST API command
85102
*
86103
* @param string $requestMethod HTTP request method
87104
* @param string $url URL
88105
* @param mixed $parameters Parameters
106+
* @param array $extraOptions key=>value pairs of curl options to pass to curl_setopt()
89107
*
90108
* @return mixed
91109
*
92110
* @throws \WebDriver\Exception\CurlExec
93111
*
94112
* @see http://saucelabs.com/docs/saucerest
95113
*/
96-
protected function execute($requestMethod, $url, $parameters = null)
114+
protected function execute($requestMethod, $url, $parameters = null, $extraOptions = array())
97115
{
98116
$extraOptions = array(
99117
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
@@ -109,7 +127,9 @@ protected function execute($requestMethod, $url, $parameters = null)
109127

110128
$url = 'https://saucelabs.com/rest/v1/' . $url;
111129

112-
list($rawResult, $info) = $this->curlService->execute($requestMethod, $url, $parameters, $extraOptions);
130+
list($rawResult, $info) = $this->curlService->execute($requestMethod, $url, $parameters, array_merge($extraOptions, $this->transientOptions));
131+
132+
$this->transientOptions = array();
113133

114134
return json_decode($rawResult, true);
115135
}

0 commit comments

Comments
 (0)