SS_HTTPRequest
class SS_HTTPRequest implements ArrayAccess
Represents a HTTP-request, including a URL that is tokenised for parsing, and a request method (GET/POST/PUT/DELETE). This is used by {@link RequestHandler} objects to decide what to do.
Caution: objects of this class are immutable, e.g. echo $request['a']; works as expected, but $request['a'] = '1'; has no effect.
The intention is that a single SS_HTTPRequest object can be passed from one object to another, each object calling match() to get the information that they need out of the URL. This is generally handled by {@link RequestHandler::handleRequest()}.
Methods
Construct a SS_HTTPRequest from a URL relative to the site root.
Allow the setting of a URL
No description
No description
No description
No description
No description
No description
No description
No description
No description
Returns all combined HTTP GET and POST parameters passed into this request. If a parameter with the same name exists in both arrays, the POST value is returned.
No description
No description
No description
Returns a possible file extension found in parsing the URL as denoted by a "."-character near the end of the URL.
Checks if the {@link SS_HTTPRequest->getExtension()} on this request matches one of the more common media types embedded into a webpage - e.g. css, png.
Add a HTTP header to the response, replacing any header of the same name.
No description
Remove an existing HTTP header
Remove an existing HTTP header by its name, e.g. "Content-Type".
Returns the URL used to generate the page
Returns true if this request an ajax request, based on custom HTTP ajax added by common JavaScript libraries, or based on an explicit "ajax" request parameter.
Enables the existence of a key-value pair in the request to be checked using array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title']
Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title')
No description
No description
Construct an SS_HTTPResponse that will deliver a file to the client.
Matches a URL pattern The pattern can contain a number of segments, separated by / (and an extension indicated by a .)
No description
Shift all the parameter values down a key space, and return the shifted value.
No description
No description
No description
No description
No description
Finds a named URL parameter (denoted by "$"-prefix in $url_handlers) from the full URL, or a parameter specified in the route table
Returns the unparsed part of the original URL separated by commas. This is used by {@link RequestHandler->handleRequest()} to determine if further URL processing is necessary.
Returns true if this is a URL that will match without shifting off any of the URL.
Shift one or more parts off the beginning of the URL.
Returns true if the URL has been completely parsed.
Returns the client IP address which originated this request.
Returns all mimetypes from the HTTP "Accept" header as an array.
No description
Gets the "real" HTTP method for a request.
Details
at line 108
__construct($httpMethod, $url, $getVars = array(), $postVars = array(), $body = null)
Construct a SS_HTTPRequest from a URL relative to the site root.
at line 127
SS_HTTPRequest
setUrl(string $url)
Allow the setting of a URL
This is here so that RootURLController can change the URL of the request without us loosing all the other info attached (like headers)
at line 147
bool
isGET()
at line 154
bool
isPOST()
at line 161
bool
isPUT()
at line 168
bool
isDELETE()
at line 175
bool
isHEAD()
at line 183
SS_HTTPRequest
setBody(string $body)
at line 191
null|string
getBody()
at line 198
array
getVars()
at line 205
array
postVars()
at line 216
array
requestVars()
Returns all combined HTTP GET and POST parameters passed into this request. If a parameter with the same name exists in both arrays, the POST value is returned.
at line 224
mixed
getVar(string $name)
at line 232
mixed
postVar(string $name)
at line 240
mixed
requestVar(string $name)
at line 253
string
getExtension()
Returns a possible file extension found in parsing the URL as denoted by a "."-character near the end of the URL.
Doesn't necessarily have to belong to an existing file, as extensions can be also used for content-type-switching.
at line 266
bool
isMedia()
Checks if the {@link SS_HTTPRequest->getExtension()} on this request matches one of the more common media types embedded into a webpage - e.g. css, png.
This is useful for things like determining wether to display a fully rendered error page or not. Note that the media file types is not at all comprehensive.
at line 276
addHeader(string $header, string $value)
Add a HTTP header to the response, replacing any header of the same name.
at line 283
array
getHeaders()
at line 293
mixed
getHeader(string $header)
Remove an existing HTTP header
at line 304
SS_HTTPRequest
removeHeader(string $header)
Remove an existing HTTP header by its name, e.g. "Content-Type".
at line 315
string
getURL(bool $includeGetVars = false)
Returns the URL used to generate the page
at line 342
boolean
isAjax()
Returns true if this request an ajax request, based on custom HTTP ajax added by common JavaScript libraries, or based on an explicit "ajax" request parameter.
at line 356
boolean
offsetExists(unknown_type $offset)
Enables the existence of a key-value pair in the request to be checked using array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title']
at line 368
unknown
offsetGet(unknown_type $offset)
Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title')
at line 375
offsetSet($offset, $value)
at line 380
offsetUnset($offset)
at line 393
static SS_HTTPResponse
send_file($fileData, $fileName, null $mimeType = null)
Construct an SS_HTTPResponse that will deliver a file to the client.
Caution: Since it requires $fileData to be passed as binary data (no stream support), it's only advisable to send small files through this method.
at line 425
array|bool
match($pattern, bool $shiftOnSuccess = false)
Matches a URL pattern The pattern can contain a number of segments, separated by / (and an extension indicated by a .)
The parts can be either literals, or, if they start with a $ they are interpreted as variables. - Literals must be provided in order to match - $Variables are optional - However, if you put ! at the end of a variable, then it becomes mandatory.
For example: - admin/crm/list will match admin/crm/$Action/$ID/$OtherID, but it won't match admin/crm/$Action!/$ClassName!
The pattern can optionally start with an HTTP method and a space. For example, "POST $Controller/$Action". This is used to define a rule that only matches on a specific HTTP method.
at line 514
array
allParams()
at line 523
string
shiftAllParams()
Shift all the parameter values down a key space, and return the shifted value.
at line 543
array
latestParams()
at line 551
string|null
latestParam(string $name)
at line 559
array
routeParams()
at line 567
SS_HTTPRequest
setRouteParams($params)
at line 575
array
params()
at line 586
string
param(string $name)
Finds a named URL parameter (denoted by "$"-prefix in $url_handlers) from the full URL, or a parameter specified in the route table
at line 599
string
remaining()
Returns the unparsed part of the original URL separated by commas. This is used by {@link RequestHandler->handleRequest()} to determine if further URL processing is necessary.
at line 610
bool
isEmptyPattern($pattern)
Returns true if this is a URL that will match without shifting off any of the URL.
This is used by the request handler to prevent infinite parsing loops.
at line 625
String|Array
shift(int $count = 1)
Shift one or more parts off the beginning of the URL.
If you specify shifting more than 1 item off, then the items will be returned as an array
at line 647
bool
allParsed()
Returns true if the URL has been completely parsed.
This will respect parsed but unshifted directory parts.
at line 657
string
getIP()
Returns the client IP address which originated this request.
at line 712
array
getAcceptMimetypes(boolean $includeQuality = false)
Returns all mimetypes from the HTTP "Accept" header as an array.
at line 724
string
httpMethod()
at line 744
static string
detect_method(string $origMethod, array $postVars)
Gets the "real" HTTP method for a request.
Used to work around browser limitations of form submissions to GET and POST, by overriding the HTTP method with a POST parameter called "_method" for PUT, DELETE, HEAD. Using GET for the "_method" override is not supported, as GET should never carry out state changes. Alternatively you can use a custom HTTP header 'X-HTTP-Method-Override' to override the original method in {@link Director::direct()}. The '_method' POST parameter overrules the custom HTTP header.