Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Public Member Functions | |
cleanopt () | |
Reset http method. | |
delete ($url, $param=array(), $options=array()) | |
HTTP DELETE method. | |
download ($requests, $options=array()) | |
Download multiple files in parallel. | |
download_one ($url, $params, $options=array()) | |
Downloads one file and writes it to the specified file handler. | |
get ($url, $params=array(), $options=array()) | |
HTTP GET method. | |
get_errno () | |
Get curl error code. | |
get_info () | |
Get curl information. | |
get_raw_response () | |
Get raw HTTP Response Headers. | |
get_security () | |
Returns the current curl security helper. | |
getResponse () | |
Get HTTP Response Headers. | |
head ($url, $options=array()) | |
HTTP HEAD method. | |
is_registered () | |
Object method to test whether site is already registered. | |
options ($url, $options=array()) | |
HTTP OPTIONS method. | |
patch ($url, $params='', $options=array()) | |
HTTP PATCH method. | |
post ($url, $params='', $options=array()) | |
HTTP POST method. | |
put ($url, $params=array(), $options=array()) | |
HTTP PUT method. | |
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. | |
send_summary () | |
Send the summary data to Brickfield. | |
set_security ($securityobject) | |
Sets the curl security helper. | |
setHeader ($header) | |
Set HTTP Request Header. | |
setopt ($options=array()) | |
Set curl options. | |
trace ($url, $options=array()) | |
HTTP TRACE method. | |
update_registration (string $apikey, string $secretkey) | |
Update registration of this site. | |
Static Public Member Functions | |
static | get_cacert () |
Get the location of ca certificates. | |
static | mock_response ($response) |
For use only in unit tests - we can pre-set the next curl response. | |
static | strip_double_headers ($input) |
When using a proxy, an additional HTTP response code may appear at the start of the header. | |
Public Attributes | |
array | $_tmp_file_post_params = [] |
temporary params value if the value is not belongs to class stored_file. | |
curl_cache false | $cache = false |
Caches http request contents. | |
bool | $emulateredirects = null |
Perform redirects at PHP level instead of relying on native cURL functionality. | |
int | $errno |
error code | |
string | $error |
error | |
array | $header = array() |
http header | |
array | $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 | |
array const | ACTION_CHECK_REGISTRATION |
Endpoint details for setting and checking a site registration. | |
array const | ACTION_SEND_SUMMARY |
Endpoint details for sending site summary data. | |
Protected Member Functions | |
call (array $command, $params='') | |
Call the specified command. | |
check_securityhelper_blocklist (string $url) | |
check_securityhelper_blocklist. | |
get_baseapiuri () | |
Get the check registration API URI. | |
get_common_headers () | |
Get the common headers used for all calls to the Brickfields endpoints. | |
get_registration_id_for_credentials (string $apikey=null, string $secretkey=null) | |
Get the registration ID for the given set of credentials. | |
get_siteurl () | |
Get a normalised URL for the site. | |
get_url_for_command (array $command) | |
Get the URL required for the command. | |
has_registration_key () | |
Whether the site currently has a registration key stored. | |
multi ($requests, $options=array()) | |
Multi HTTP Requests This function could run multi-requests in parallel. | |
request ($url, $options=array()) | |
Single HTTP Request. | |
reset_request_state_vars () | |
Helper function to reset the request state vars. | |
set_headers (array $headers) | |
Set headers on the request from the specified list of headers. | |
|
protected |
Call the specified command.
array | $command | The command to call, for example see self\ACTION_REGISTER |
array | string | $params | The params provided to the call |
string | The response body |
|
protectedinherited |
check_securityhelper_blocklist.
Checks whether the given URL is blocked by checking both plugin's security helpers and core curl security helper or any curl security helper that passed to curl class constructor. If ignoresecurity is set to true, skip checking and consider the url is not blocked. This augments all installed plugin's security helpers if there is any.
string | $url | the url to check. |
?string | - an error message if URL is blocked or null if URL is not blocked. |
|
inherited |
HTTP DELETE method.
string | $url | |
array | $param | |
array | $options |
string |
|
inherited |
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 |
|
inherited |
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 |
|
inherited |
HTTP GET method.
string | $url | |
?array | $params | |
array | $options |
string |
|
protected |
Get the check registration API URI.
string |
|
staticinherited |
Get the location of ca certificates.
string | absolute file path or empty if default used |
|
protected |
Get the common headers used for all calls to the Brickfields endpoints.
array |
|
inherited |
Get curl error code.
int |
|
inherited |
Get curl information.
array |
|
inherited |
Get raw HTTP Response Headers.
array | of strings |
|
protected |
Get the registration ID for the given set of credentials.
null | string | $apikey | The API key to use for the registration attempt |
null | string | $secretkey | The secret key to use |
null|string | The registration ID if registration was successful, or null if not |
|
inherited |
Returns the current curl security helper.
core\files\curl_security_helper | instance. |
|
protected |
Get a normalised URL for the site.
string |
|
protected |
Get the URL required for the command.
array | $command | The command to call, for example see self\ACTION_REGISTER |
string | The complete URL |
|
inherited |
Get HTTP Response Headers.
array | of arrays |
|
protected |
Whether the site currently has a registration key stored.
bool |
|
inherited |
HTTP HEAD method.
string | $url | |
array | $options |
string |
tool_brickfield\brickfieldconnect::is_registered | ( | ) |
Object method to test whether site is already registered.
bool |
Reimplemented in tool_brickfield\mock_brickfieldconnect.
|
staticinherited |
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 |
|
protectedinherited |
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.
|
inherited |
HTTP OPTIONS method.
string | $url | |
array | $options |
string |
|
inherited |
HTTP PATCH method.
string | $url | |
array | string | $params | |
array | $options |
string |
|
inherited |
HTTP POST method.
string | $url | |
array | string | $params | |
array | $options |
string |
|
inherited |
HTTP PUT method.
string | $url | |
array | $params | |
array | $options |
?string |
|
protectedinherited |
Single HTTP Request.
string | $url | The URL to request |
array | $options |
string |
|
protectedinherited |
Helper function to reset the request state vars.
void. |
tool_brickfield\brickfieldconnect::send_summary | ( | ) |
|
protected |
Set headers on the request from the specified list of headers.
array | $headers | An array of header name => value |
|
inherited |
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. |
|
inherited |
Set HTTP Request Header.
array | string | $header |
|
inherited |
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. |
|
staticinherited |
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 |
|
inherited |
HTTP TRACE method.
string | $url | |
array | $options |
string |
tool_brickfield\brickfieldconnect::update_registration | ( | string | $apikey, |
string | $secretkey ) |
Update registration of this site.
string | $apikey | The API key to use for the registration attempt |
string | $secretkey | The secret key to use |
bool |
Reimplemented in tool_brickfield\mock_brickfieldconnect.
|
inherited |
Perform redirects at PHP level instead of relying on native cURL functionality.
Always true now.
array const tool_brickfield\brickfieldconnect::ACTION_CHECK_REGISTRATION |
Endpoint details for setting and checking a site registration.
array const tool_brickfield\brickfieldconnect::ACTION_SEND_SUMMARY |
Endpoint details for sending site summary data.