forked from rwincewicz/php_listeners
-
Notifications
You must be signed in to change notification settings - Fork 8
/
TavernaCurlConnection.php
77 lines (65 loc) · 2.04 KB
/
TavernaCurlConnection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require_once 'tuque/HttpConnection.php';
/**
*This class defines extends Tuque's CurlConnectioin
*/
class TavernaCurlConnection extends CurlConnection {
/**
* Put a request to the server. This is primarily used for
* send strings using PUT method
*
* @todo Test this for send string to taverna server
*
* @param string $url
* The URL to post the request to. Should start with the
* protocol. For example: http://.
* @param string $type
* This paramarter must be one of: string, file.
* @param string $data
* What this parameter contains is decided by the $type parameter.
* @param string $content_type
* The content type header to set for the post request.
*
* @throws HttpConnectionException
*
* @return array
* Associative array containing:
* * $return['status'] = The HTTP status code
* * $return['headers'] = The HTTP headers of the reply
* * $return['content'] = The body of the HTTP reply
*/
public function tavernaPutRequest($url, $type = 'none', $data , $content_type = NULL) {
$this->setupCurlContext($url);
curl_setopt(self::$curlContext, CURLOPT_CUSTOMREQUEST, 'PUT');
//curl_setopt(self::$curlContext, CURLOPT_PUT, TRUE);
switch (strtolower($type)) {
case 'string':
if ($content_type) {
$headers = array("Content-Type: $content_type");
}
else {
$headers = array("Content-Type: text/plain");
}
curl_setopt(self::$curlContext, CURLOPT_HTTPHEADER, $headers);
curl_setopt(self::$curlContext, CURLOPT_POSTFIELDS, $data);
break;
case 'none':
curl_setopt(self::$curlContext, CURLOPT_POSTFIELDS, array());
break;
default:
throw new HttpConnectionException('$type must be: string. ' . "($type).", 0);
}
$exception = NULL;
try {
$results = $this->doCurlRequest();
} catch (HttpConnectionException $e)
{
$exception = $e;
}
if($exception) {
throw $exception;
}
return $results;
}
}
?>