Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Public Member Functions | |
__construct ($settings=array()) | |
Curl constructor. More... | |
cleanopt () | |
Reset http method. | |
delete ($url, $param=array(), $options=array()) | |
HTTP DELETE method. More... | |
download ($requests, $options=array()) | |
Download multiple files in parallel. More... | |
download_one ($url, $params, $options=array()) | |
Downloads one file and writes it to the specified file handler. More... | |
get ($url, $params=array(), $options=array()) | |
HTTP GET method. More... | |
get_errno () | |
Get curl error code. More... | |
get_info () | |
Get curl information. More... | |
get_raw_response () | |
Get raw HTTP Response Headers. More... | |
get_security () | |
Returns the current curl security helper. More... | |
getResponse () | |
Get HTTP Response Headers. More... | |
head ($url, $options=array()) | |
HTTP HEAD method. More... | |
options ($url, $options=array()) | |
HTTP OPTIONS method. More... | |
patch ($url, $params='', $options=array()) | |
HTTP PATCH method. More... | |
post ($url, $params='', $options=array()) | |
HTTP POST method. More... | |
put ($url, $params=array(), $options=array()) | |
HTTP PUT method. More... | |
resetcookie () | |
Reset Cookie. | |
resetHeader () | |
Resets the HTTP Request headers (to prepare for the new request) | |
resetopt () | |
Resets the CURL options that have already been set. | |
set_security ($securityobject) | |
Sets the curl security helper. More... | |
setHeader ($header) | |
Set HTTP Request Header. More... | |
setopt ($options=array()) | |
Set curl options. More... | |
trace ($url, $options=array()) | |
HTTP TRACE method. More... | |
Static Public Member Functions | |
static | get_cacert () |
Get the location of ca certificates. More... | |
static | mock_response ($response) |
For use only in unit tests - we can pre-set the next curl response. More... | |
static | strip_double_headers ($input) |
When using a proxy, an additional HTTP response code may appear at the start of the header. More... | |
Public Attributes | |
bool | $cache = false |
Caches http request contents. | |
bool | $emulateredirects = null |
Perform redirects at PHP level instead of relying on native cURL functionality. More... | |
int | $errno |
error code | |
string | $error |
error | |
array | $header = array() |
http header | |
string | $info |
cURL information | |
bool | $proxy = null |
Uses proxy, null means automatic based on URL. | |
array | $rawresponse = array() |
Raw response headers, needed for BC in download_file_content(). | |
array | $response = array() |
http's response | |
string | $version = '0.4 dev' |
library version | |
Protected Member Functions | |
multi ($requests, $options=array()) | |
Multi HTTP Requests This function could run multi-requests in parallel. More... | |
request ($url, $options=array()) | |
Single HTTP Request. More... | |
reset_request_state_vars () | |
Helper function to reset the request state vars. More... | |
curl::__construct | ( | $settings = array() | ) |
Curl constructor.
Allowed settings are: proxy: (bool) use proxy server, null means autodetect non-local from url debug: (bool) use debug output cookie: (string) path to cookie file, false if none cache: (bool) use cache module_cache: (string) type of cache securityhelper: (core::files::curl_security_helper_base) helper object providing URL checking for requests. ignoresecurity: (bool) set true to override and ignore the security helper when making requests.
array | $settings |
curl::delete | ( | $url, | |
$param = array() , |
|||
$options = array() |
|||
) |
HTTP DELETE method.
string | $url | |
array | $param | |
array | $options |
bool |
curl::download | ( | $requests, | |
$options = array() |
|||
) |
Download multiple files in parallel.
Calls multi() with specific download headers
$c = new curl(); $file1 = fopen('a', 'wb'); $file2 = fopen('b', 'wb'); $c->download(array( array('url'=>'http://localhost/', 'file'=>$file1), array('url'=>'http://localhost/20/', 'file'=>$file2) )); fclose($file1); fclose($file2);
or
$c = new curl(); $c->download(array( array('url'=>'http://localhost/', 'filepath'=>'/tmp/file1.tmp'), array('url'=>'http://localhost/20/', 'filepath'=>'/tmp/file2.tmp') ));
array | $requests | An array of files to request { url => url to download the file [required] file => file handler, or filepath => file path } If 'file' and 'filepath' parameters are both specified in one request, the open file handle in the 'file' parameter will take precedence and 'filepath' will be ignored. |
array | $options | An array of options to set |
array | An array of results |
curl::download_one | ( | $url, | |
$params, | |||
$options = array() |
|||
) |
Downloads one file and writes it to the specified file handler.
$c = new curl(); $file = fopen('savepath', 'w'); $result = $c->download_one('http://localhost/', null, array('file' => $file, 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); fclose($file); $download_info = $c->get_info(); if ($result === true) { // file downloaded successfully } else { $error_text = $result; $error_code = $c->get_errno(); }
$c = new curl(); $result = $c->download_one('http://localhost/', null, array('filepath' => 'savepath', 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); // ... see above, no need to close handle and remove file if unsuccessful
string | $url | |
array | null | $params | key-value pairs to be added to $url as query string |
array | $options | request options. Must include either 'file' or 'filepath' |
bool|string | true on success or error string on failure |
curl::get | ( | $url, | |
$params = array() , |
|||
$options = array() |
|||
) |
HTTP GET method.
string | $url | |
array | $params | |
array | $options |
bool |
|
static |
Get the location of ca certificates.
string | absolute file path or empty if default used |
curl::get_errno | ( | ) |
Get curl error code.
int |
curl::get_info | ( | ) |
Get curl information.
string |
curl::get_raw_response | ( | ) |
Get raw HTTP Response Headers.
array | of strings |
curl::get_security | ( | ) |
Returns the current curl security helper.
core::files::curl_security_helper | instance. |
curl::getResponse | ( | ) |
Get HTTP Response Headers.
array | of arrays |
curl::head | ( | $url, | |
$options = array() |
|||
) |
|
static |
For use only in unit tests - we can pre-set the next curl response.
This is useful for unit testing APIs that call external systems.
string | $response |
|
protected |
Multi HTTP Requests This function could run multi-requests in parallel.
array | $requests | An array of files to request |
array | $options | An array of options to set |
array | An array of results |
Reimplemented in oauth2_client.
curl::options | ( | $url, | |
$options = array() |
|||
) |
HTTP OPTIONS method.
string | $url | |
array | $options |
bool |
curl::patch | ( | $url, | |
$params = '' , |
|||
$options = array() |
|||
) |
HTTP PATCH method.
string | $url | |
array | string | $params | |
array | $options |
bool |
curl::post | ( | $url, | |
$params = '' , |
|||
$options = array() |
|||
) |
HTTP POST method.
string | $url | |
array | string | $params | |
array | $options |
bool |
Reimplemented in microsoft_skydrive.
curl::put | ( | $url, | |
$params = array() , |
|||
$options = array() |
|||
) |
HTTP PUT method.
string | $url | |
array | $params | |
array | $options |
bool |
|
protected |
Single HTTP Request.
string | $url | The URL to request |
array | $options |
bool |
|
protected |
Helper function to reset the request state vars.
void. |
curl::set_security | ( | $securityobject | ) |
Sets the curl security helper.
core::files::curl_security_helper | $securityobject | instance/subclass of the base curl_security_helper class. |
bool | true if the security helper could be set, false otherwise. |
curl::setHeader | ( | $header | ) |
Set HTTP Request Header.
array | $header |
curl::setopt | ( | $options = array() | ) |
Set curl options.
Do not use the curl constants to define the options, pass a string corresponding to that constant. Ie. to set CURLOPT_MAXREDIRS, pass array('CURLOPT_MAXREDIRS' => 10) or array('maxredirs' => 10) to this method.
array | $options | If array is null, this function will reset the options to default value. |
void |
coding_exception | If an option uses constant value instead of option name. |
|
static |
When using a proxy, an additional HTTP response code may appear at the start of the header.
For example, when using https over a proxy there may be 'HTTP/1.0 200 Connection Established'. Other codes are also possible and some may come with their own headers.
If using the return value containing all headers, this function can be called to remove unwanted doubles.
Note that it is not possible to distinguish this situation from valid data unless you know the actual response part (below the headers) will not be included in this string, or else will not 'look like' HTTP headers. As a result it is not safe to call this function for general data.
string | $input | Input HTTP response |
string | HTTP response with additional headers stripped if any |
curl::trace | ( | $url, | |
$options = array() |
|||
) |
HTTP TRACE method.
string | $url | |
array | $options |
bool |
bool curl::$emulateredirects = null |
Perform redirects at PHP level instead of relying on native cURL functionality.
Always true now.