NullHTTPRequest
class NullHTTPRequest extends HTTPRequest
Implements the "Null Object" pattern for a missing http request.
Set on controllers on construction time, typically overwritten by {@link Controller->handleRequest()} and {@link Controller->handleAction()} later on.
Methods
Construct a HTTPRequest from a URL relative to the site root.
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.
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 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.
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')
Construct an 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 .)
Shift all the parameter values down a key space, and return the shifted value.
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 all mimetypes from the HTTP "Accept" header as an array.
Gets the "real" HTTP method for a request.
Details
at line 13
__construct()
Construct a HTTPRequest from a URL relative to the site root.
in HTTPRequest at line 176
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)
in HTTPRequest at line 200
bool
isGET()
in HTTPRequest at line 208
bool
isPOST()
in HTTPRequest at line 216
bool
isPUT()
in HTTPRequest at line 224
bool
isDELETE()
in HTTPRequest at line 232
bool
isHEAD()
in HTTPRequest at line 241
HTTPRequest
setBody(string $body)
in HTTPRequest at line 250
null|string
getBody()
in HTTPRequest at line 258
array
getVars()
in HTTPRequest at line 266
array
postVars()
in HTTPRequest at line 278
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.
in HTTPRequest at line 287
mixed
getVar(string $name)
in HTTPRequest at line 299
mixed
postVar(string $name)
in HTTPRequest at line 311
mixed
requestVar(string $name)
in HTTPRequest at line 330
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.
in HTTPRequest at line 344
bool
isMedia()
Checks if the {@link 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 whether to display a fully rendered error page or not. Note that the media file types is not at all comprehensive.
in HTTPRequest at line 355
addHeader(string $header, string $value)
Add a HTTP header to the response, replacing any header of the same name.
in HTTPRequest at line 365
array
getHeaders()
in HTTPRequest at line 376
mixed
getHeader(string $header)
Remove an existing HTTP header
in HTTPRequest at line 389
HTTPRequest
removeHeader(string $header)
Remove an existing HTTP header by its name, e.g. "Content-Type".
in HTTPRequest at line 402
string
getURL(bool $includeGetVars = false)
Returns the URL used to generate the page
in HTTPRequest at line 425
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.
in HTTPRequest at line 440
bool
offsetExists(string $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']
in HTTPRequest at line 451
mixed
offsetGet(string $offset)
Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title')
in HTTPRequest at line 456
offsetSet($offset, $value)
in HTTPRequest at line 461
offsetUnset($offset)
in HTTPRequest at line 478
static HTTPResponse
send_file($fileData, $fileName, null $mimeType = null)
Construct an 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.
in HTTPRequest at line 511
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.
in HTTPRequest at line 611
array
allParams()
in HTTPRequest at line 621
string
shiftAllParams()
Shift all the parameter values down a key space, and return the shifted value.
in HTTPRequest at line 642
array
latestParams()
in HTTPRequest at line 651
string|null
latestParam(string $name)
in HTTPRequest at line 663
array
routeParams()
in HTTPRequest at line 672
HTTPRequest
setRouteParams($params)
in HTTPRequest at line 681
array
params()
in HTTPRequest at line 693
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
in HTTPRequest at line 710
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.
in HTTPRequest at line 722
bool
isEmptyPattern(string $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.
in HTTPRequest at line 741
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
in HTTPRequest at line 768
bool
allParsed()
Returns true if the URL has been completely parsed.
This will respect parsed but unshifted directory parts.
in HTTPRequest at line 776
string
getHost()
in HTTPRequest at line 786
string
getIP()
Returns the client IP address which originated this request.
in HTTPRequest at line 798
$this
setIP($ip)
Sets the client IP address which originated this request.
Use setIPFromHeaderValue if assigning from header value.
in HTTPRequest at line 815
array
getAcceptMimetypes(boolean $includeQuality = false)
Returns all mimetypes from the HTTP "Accept" header as an array.
in HTTPRequest at line 828
string
httpMethod()
in HTTPRequest at line 839
string
getScheme()
Return the URL scheme (e.g. "http" or "https").
Equivalent to PSR-7 getUri()->getScheme()
in HTTPRequest at line 851
$this
setScheme(string $scheme)
Set the URL scheme (e.g. "http" or "https").
Equivalent to PSR-7 getUri()->getScheme(),
in HTTPRequest at line 873
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. The '_method' POST parameter overrules the custom HTTP header.
in HTTPRequest at line 890
bool
hasSession()
Determines whether the request has a session