vB_Utility_Url
in package
Uses
vB_Utility_Trait_NoSerialize
Table of Contents
- CLOSECONNECTION = 1024
- CUSTOMREQUEST = 16384
- DIEONMAXSIZE = 65536
- ENCODING = 32
- ERROR_MAXSIZE = 1
- ERROR_NOFILE = 2
- ERROR_NOLIB = 8
- FOLLOWLOCATION = 2048
- HEADER = 8
- HTTPHEADER = 256
- MAXREDIRS = 4096
- MAXSIZE = 32768
- NOBODY = 8192
- POST = 4
- POSTFIELDS = 16
- STATE_BODY = 3
- STATE_HEADERS = 1
- STATE_LOCATION = 2
- TEMPFILENAME = 262144
- TIMEOUT = 2
- URL = 1
- VALIDSSLONLY = 131072
- $allowedports : mixed
- $allowedsiteroot : mixed
- $allowip : mixed
- $allowlocal : mixed
- $bitoptions : mixed
- $ch : mixed
- $errror : mixed
- $ip : mixed
- $max_limit_reached : mixed
- $options : mixed
- $response_header : mixed
- $response_length : mixed
- $response_text : mixed
- $string : mixed
- $tempfilepointer : mixed
- __construct() : mixed
- Constructor
- __destruct() : mixed
- This deals with the case that people forget to either unlink or move the file.
- __serialize() : mixed
- __sleep() : mixed
- __unserialize() : mixed
- __wakeup() : mixed
- curl_callback_header() : int
- Callback for handling headers
- curl_callback_response() : int
- Callback for handling the request body
- get() : false
- Perform a GET request
- getError() : int
- Return Error
- isSiteUrl() : mixed
- post() : false
- Perform a POST request
- postJson() : false
- Perform a POST request using a JSON post body
- reset() : mixed
- setOption() : mixed
- On/Off options
- buildHeaders() : mixed
- closeTempFile() : mixed
- deleteTempFile() : mixed
- exec() : bool
- Performs fetching of the file if possible
- execCurl() : string|false
- Actually load the url from the interweb
- formatResponse() : mixed
- normalizepath() : mixed
- rebuildUrl() : mixed
- Rebuild the a url from the info components
- resetPageLoad() : mixed
- Clears all previous request info
- setCurlOptions() : mixed
- setError() : mixed
- Set Error
- validateUrl() : mixed
- Determine if the url is safe to load
Constants
CLOSECONNECTION
public
mixed
CLOSECONNECTION
= 1024
CUSTOMREQUEST
public
mixed
CUSTOMREQUEST
= 16384
DIEONMAXSIZE
public
mixed
DIEONMAXSIZE
= 65536
ENCODING
public
mixed
ENCODING
= 32
ERROR_MAXSIZE
public
mixed
ERROR_MAXSIZE
= 1
ERROR_NOFILE
public
mixed
ERROR_NOFILE
= 2
ERROR_NOLIB
public
mixed
ERROR_NOLIB
= 8
FOLLOWLOCATION
public
mixed
FOLLOWLOCATION
= 2048
HEADER
public
mixed
HEADER
= 8
HTTPHEADER
public
mixed
HTTPHEADER
= 256
MAXREDIRS
public
mixed
MAXREDIRS
= 4096
MAXSIZE
public
mixed
MAXSIZE
= 32768
NOBODY
public
mixed
NOBODY
= 8192
POST
public
mixed
POST
= 4
POSTFIELDS
public
mixed
POSTFIELDS
= 16
STATE_BODY
public
mixed
STATE_BODY
= 3
STATE_HEADERS
public
mixed
STATE_HEADERS
= 1
STATE_LOCATION
public
mixed
STATE_LOCATION
= 2
TEMPFILENAME
public
mixed
TEMPFILENAME
= 262144
TIMEOUT
public
mixed
TIMEOUT
= 2
URL
public
mixed
URL
= 1
VALIDSSLONLY
public
mixed
VALIDSSLONLY
= 131072
Properties
$allowedports
private
mixed
$allowedports
$allowedsiteroot
private
mixed
$allowedsiteroot
$allowip
private
mixed
$allowip
$allowlocal
private
mixed
$allowlocal
$bitoptions
private
mixed
$bitoptions
= 0
$ch
private
mixed
$ch
$errror
private
mixed
$errror
= 0
$ip
private
mixed
$ip
$max_limit_reached
private
mixed
$max_limit_reached
= alse
$options
private
mixed
$options
= array()
$response_header
private
mixed
$response_header
= ''
$response_length
private
mixed
$response_length
= 0
$response_text
private
mixed
$response_text
= ''
$string
private
mixed
$string
$tempfilepointer
private
mixed
$tempfilepointer
Methods
__construct()
Constructor
public
__construct(vB_Utility_String $string, mixed $validationOptions) : mixed
Parameters
- $string : vB_Utility_String
-
-- the properly configured string object.
- $validationOptions : mixed
Return values
mixed —__destruct()
This deals with the case that people forget to either unlink or move the file.
public
__destruct() : mixed
Return values
mixed —__serialize()
public
__serialize() : mixed
Return values
mixed —__sleep()
public
__sleep() : mixed
Return values
mixed —__unserialize()
public
__unserialize(mixed $serialized) : mixed
Parameters
- $serialized : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —curl_callback_header()
Callback for handling headers
public
curl_callback_header(mixed $ch, mixed $string) : int
Parameters
- $ch : mixed
- $string : mixed
Return values
int —length of the request
curl_callback_response()
Callback for handling the request body
public
curl_callback_response(mixed $ch, mixed $response) : int
Parameters
- $ch : mixed
- $response : mixed
Return values
int —length of the request
get()
Perform a GET request
public
get(string $url) : false
Parameters
- $url : string
Return values
false —| array -- array headers -- the httpheaders return. Empty if the HEADER is not set -- string body -- the body of the request. Empty if NOBODY is set Returns false on error
getError()
Return Error
public
getError() : int
Return values
int —errorcode
isSiteUrl()
public
isSiteUrl(mixed $urlinfo) : mixed
Parameters
- $urlinfo : mixed
Return values
mixed —post()
Perform a POST request
public
post(string $url, array<string|int, mixed>|string $postdata) : false
Parameters
- $url : string
- $postdata : array<string|int, mixed>|string
-
-- the data as either an array or "query param" string
Return values
false —| array -- array headers -- the httpheaders return. Empty if the HEADER is not set -- string body -- the body of the request. Empty if NOBODY is set Returns false on error
postJson()
Perform a POST request using a JSON post body
public
postJson(string $url, string $postdata) : false
This performs as post using a custom JSON request (popular with REST APIs) instead of a standard x-www-form-urlencoded format
Parameters
- $url : string
- $postdata : string
-
-- the JSON encoded request.
Return values
false —| array -- array headers -- the httpheaders return. Empty if the HEADER is not set -- string body -- the body of the request. Empty if NOBODY is set Returns false on error
reset()
public
reset() : mixed
Return values
mixed —setOption()
On/Off options
public
setOption(mixed $option, mixed $extra) : mixed
Parameters
- $option : mixed
- $extra : mixed
Return values
mixed —buildHeaders()
private
buildHeaders(mixed $data) : mixed
Parameters
- $data : mixed
Return values
mixed —closeTempFile()
private
closeTempFile() : mixed
Return values
mixed —deleteTempFile()
private
deleteTempFile() : mixed
Return values
mixed —exec()
Performs fetching of the file if possible
private
exec(mixed $extraheaders) : bool
Parameters
- $extraheaders : mixed
Return values
bool —execCurl()
Actually load the url from the interweb
private
execCurl(string $url) : string|false
Parameters
- $url : string
Tags
Return values
string|false —The result of curl_exec
formatResponse()
private
formatResponse() : mixed
Return values
mixed —normalizepath()
private
normalizepath(mixed $path) : mixed
Parameters
- $path : mixed
Return values
mixed —rebuildUrl()
Rebuild the a url from the info components
private
rebuildUrl( $urlinfo) : mixed
This ensures that we know for certain that the url we validated is the the one that we are fetching. Due to bugs in parse_url it's possible to slip something through the validation function because it appears in the wrong component. So we validate the hostname that appears in the array but the actual url will be interpreted differently by curl -- for example:
http://127.0.0.1:11211#@orange.tw/xxx
The host name is '127.0.0.1' and port is 11211 but parse_url will return host orange.tw and no port value.
the expectation is that the values passed to this function passed validateUrl
Parameters
Return values
mixed —resetPageLoad()
Clears all previous request info
private
resetPageLoad() : mixed
Return values
mixed —setCurlOptions()
private
setCurlOptions(mixed $ch, mixed $extraheaders) : mixed
Parameters
- $ch : mixed
- $extraheaders : mixed
Return values
mixed —setError()
Set Error
private
setError(int $errorcode) : mixed
Parameters
- $errorcode : int
Return values
mixed —validateUrl()
Determine if the url is safe to load
private
validateUrl( $urlinfo) : mixed