NullHTTPRequest
class NullHTTPRequest extends HTTPRequest (View source)
Implements the "Null Object" pattern for a missing http request.
Set on controllers on construction time, typically overwritten by Controller->handleRequest()} and {@link Controller->handleAction() later on.
Properties
protected | string | $url | from HTTPRequest | |
protected | array | $dirParts | The non-extension parts of the passed URL as an array, originally exploded by the "/" separator. |
from HTTPRequest |
protected | string | $extension | The URL extension (if present) |
from HTTPRequest |
protected | string | $httpMethod | The HTTP method in all uppercase: GET/PUT/POST/DELETE/HEAD |
from HTTPRequest |
protected | string | $scheme | The URL scheme in lowercase: http or https |
from HTTPRequest |
protected | string | $ip | The client IP address |
from HTTPRequest |
protected | array | $getVars | Contains all HTTP GET parameters passed into this request. |
from HTTPRequest |
protected | array | $postVars | Contains all HTTP POST parameters passed into this request. |
from HTTPRequest |
protected | array | $headers | HTTP Headers like "Content-Type: text/xml" |
from HTTPRequest |
protected | string | $body | Raw HTTP body, used by PUT and POST requests. |
from HTTPRequest |
protected | array | $allParams | Contains an associative array of all arguments matched in all calls to RequestHandler->handleRequest(). |
from HTTPRequest |
protected | array | $latestParams | Contains an associative array of all arguments matched in the current call from RequestHandler->handleRequest(), as denoted with a "$"-prefix in the $url_handlers definitions. |
from HTTPRequest |
protected | array | $routeParams | Contains an associative array of all arguments explicitly set in the route table for the current request. |
from HTTPRequest |
protected | int | $unshiftedButParsedParts | from HTTPRequest | |
protected | Session | $session | from HTTPRequest |
Methods
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 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.
Returns a HTTP Header by name if found in the request
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 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.
Sets the client IP address which originated this request.
Returns all mimetypes from the HTTP "Accept" header as an array.
Explicitly set the HTTP method for this request.
Set the URL scheme (e.g. "http" or "https").
Details
__construct()
Construct a HTTPRequest from a URL relative to the site root.
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 losing all the other info attached (like headers)
bool
isGET()
No description
bool
isPOST()
No description
bool
isPUT()
No description
bool
isDELETE()
No description
bool
isHEAD()
No description
HTTPRequest
setBody(string $body)
No description
null|string
getBody()
No description
array
getVars()
No description
array
postVars()
No description
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.
mixed
getVar(string $name)
No description
mixed
postVar(string $name)
No description
mixed
requestVar(string $name)
No description
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.
bool
isMedia()
Checks if the 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.
addHeader(string $header, string $value)
Add a HTTP header to the response, replacing any header of the same name.
array
getHeaders()
No description
mixed
getHeader(string $header)
Returns a HTTP Header by name if found in the request
HTTPRequest
removeHeader(string $header)
Remove an existing HTTP header by its name, e.g. "Content-Type".
string
getURL(bool $includeGetVars = false)
Returns the URL used to generate the page
bool
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.
bool
offsetExists(mixed $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']
mixed
offsetGet(mixed $offset)
Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title')
void
offsetSet(mixed $offset, mixed $value)
No description
void
offsetUnset(mixed $offset)
No description
static HTTPResponse
send_file(string $fileData, string $fileName, string|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.
This function needs to be called inside the controller’s response, e.g.:
$this->setResponse(HTTPRequest::send_file('the content', 'filename.txt'));
array|bool
match(string $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.
array
allParams()
No description
string
shiftAllParams()
Shift all the parameter values down a key space, and return the shifted value.
array
latestParams()
No description
string|null
latestParam(string $name)
No description
array
routeParams()
No description
HTTPRequest
setRouteParams(array $params)
No description
array
params()
No description
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
string
remaining()
Returns the unparsed part of the original URL separated by commas. This is used by RequestHandler->handleRequest() to determine if further URL processing is necessary.
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.
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
bool
allParsed()
Returns true if the URL has been completely parsed.
This will respect parsed but unshifted directory parts.
string
getHost()
No description
string
getIP()
Returns the client IP address which originated this request.
$this
setIP(string $ip)
Sets the client IP address which originated this request.
Use setIPFromHeaderValue if assigning from header value.
array
getAcceptMimetypes(bool $includeQuality = false)
Returns all mimetypes from the HTTP "Accept" header as an array.
string
httpMethod()
No description
$this
setHttpMethod(string $method)
Explicitly set the HTTP method for this request.
string
getScheme()
Return the URL scheme (e.g. "http" or "https").
Equivalent to PSR-7 getUri()->getScheme()
$this
setScheme(string $scheme)
Set the URL scheme (e.g. "http" or "https").
Equivalent to PSR-7 getUri()->getScheme(),
bool
hasSession()
Determines whether the request has a session
Session
getSession()
No description
$this
setSession(Session $session)
No description