Curl
in component
Simplifies http requests. Optional.
Originally it was created for fetching images from external services but later we extended it with features to make api calls.
Table of Contents
Constants
Properties
Methods
- encodeURL() : string
- Encodes an image URL to a url-compliant string.
- getFileContentsByUrl() : string|null
- Downloads a file by url and follows up to 5 redirects. Partial download is supported, see
http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html. File name and content type of the
last file are available through getLastFileInfo(). - getLastError() : string
- Returns the last error.
- getLastFileInfo() : array<string|int, mixed>
- Returns information about the last downloaded file ('filename', 'content-type').
- parseContentDisposition() : array<string|int, mixed>
- Parses a content disposition string like:
attachment;filename="BK914.jpg";filename*=UTF-8''BK914.jpg - request() : string|null|false
- Sends an http request and follows up to 5 redirects. The request is sent with POST when $data
is not empty. - parseHttpHeader() : array<string|int, mixed>|false
- Parses an http header block.
Constants
MAX_RESOLVE_ATTEMPTS
public
mixed
MAX_RESOLVE_ATTEMPTS
= 3
Properties
$last_file_info
protected
mixed
$last_file_info
= array()
$lastError
protected
mixed
$lastError
= ''
Methods
encodeURL()
Encodes an image URL to a url-compliant string.
public
encodeURL(mixed $url) : string
$url — url to encode.
Parameters
- $url : mixed
Return values
stringgetFileContentsByUrl()
Downloads a file by url and follows up to 5 redirects. Partial download is supported, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html. File name and content type of the last file are available through getLastFileInfo().
public
getFileContentsByUrl(mixed $url[, mixed $from = 0 ]) : string|null
$url — file url. $from — byte offset to start downloading from.
Parameters
- $url : mixed
- $from : mixed = 0
Return values
string|null —File contents; null on error (see getLastError()).
getLastError()
Returns the last error.
public
getLastError() : string
Return values
stringgetLastFileInfo()
Returns information about the last downloaded file ('filename', 'content-type').
public
getLastFileInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>parseContentDisposition()
Parses a content disposition string like: attachment;filename="BK914.jpg";filename*=UTF-8''BK914.jpg
public
parseContentDisposition(mixed $str) : array<string|int, mixed>
$str — content disposition string.
Parameters
- $str : mixed
Return values
array<string|int, mixed> —Name/value pairs.
request()
Sends an http request and follows up to 5 redirects. The request is sent with POST when $data is not empty.
public
request(mixed $url[, mixed $data = array() ][, mixed $options = array() ]) : string|null|false
$url — request url. $data — plain text or array of fields. $options — array of possible values: timeout — request timeout in seconds (8 by default); user-agent — text for user-agent value; extra_headers — array of extra headers (name => value); webauth_username, webauth_password — credentials for http authorization.
Parameters
- $url : mixed
- $data : mixed = array()
- $options : mixed = array()
Return values
string|null|false —Response body; null or false on error (see getLastError()).
parseHttpHeader()
Parses an http header block.
protected
parseHttpHeader(mixed $header) : array<string|int, mixed>|false
$header — header block of the response.
Parameters
- $header : mixed
Return values
array<string|int, mixed>|false —False on error. On success an array like:
array(
'status' => array('http_version' => ..., 'status_code' => ..., 'reason_phrase' => ...),
'headers' => array('