Represents the context for the handling of a request in Vert.x-Web.
A new instance is created for each HTTP request that is received in the of the router.
The same instance is passed to any matching request or failure handlers during the routing of the request or failure.
The context provides access to the and and allows you to maintain arbitrary data that lives for the lifetime of the context. Contexts are discarded once they have been routed to the handler for the request.
The context also provides access to the @see \io\vertx\jphp\ext\web\Session, cookies and body for the request, given the correct handlers in the application.
| package |
Default |
|---|
__construct()
acceptableLanguages() : array
When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.
arrayThe best matched language for the request
acceptableLocales() : array
When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.
| deprecated | |
|---|---|
arraythe best matched locale for the request
addBodyEndHandler( $arg0) : integer
The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire. Do not use this for resource cleanup as this handler might never get called (e.g. if the connection is reset).
callable
integerthe id of the handler. This can be used if you later want to remove the handler.
addCookie( $arg0) : $this
Cookie
$thisa reference to this, so the API can be used fluently
addHeadersEndHandler( $arg0) : integer
callable
integerthe id of the handler. This can be used if you later want to remove the handler.
clearUser() : void
currentRoute() : \io\vertx\jphp\ext\web\Route
fail( $arg0) : void
This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response will be sent. param $statusCode [integer] the HTTP status code fail($statusCode) Fail the context with the specified throwable.
This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response with status code 500 will be sent. param $throwable [\Exception] a throwable representing the failure fail($throwable)
\Exception | integer
failed() : boolean
booleantrue if the context is being routed to failure handlers.
failure() : \Exception
| see |
\io\vertx\jphp\ext\web\RoutingContext::fail
then this will return that throwable. It can be used by failure handlers to render a response, e.g. create a failure response page. |
|---|---|
\Exceptionthe throwable used when signalling failure
fileUploads() : array
arraya set of fileuploads (if any) for the request. The context must have first been routed to a {@link io.vertx.ext.web.handler.BodyHandler} for this to work.
get( $arg0) : mixed
string
mixedthe data
getAcceptableContentType() : string
stringthe most acceptable content type.
getBody() : \io\vertx\jphp\core\buffer\Buffer
\io\vertx\jphp\core\buffer\BufferGet the entire HTTP request body as a {@link Buffer}. The context must have first been routed to a {@link io.vertx.ext.web.handler.BodyHandler} for this to be populated.
getBodyAsJson() : array
arrayGet the entire HTTP request body as a {@link JsonObject}. The context must have first been routed to a {@link io.vertx.ext.web.handler.BodyHandler} for this to be populated.
getBodyAsJsonArray() : array
arrayGet the entire HTTP request body as a {@link JsonArray}. The context must have first been routed to a {@link io.vertx.ext.web.handler.BodyHandler} for this to be populated.
getBodyAsString( $arg0 = null) : string
Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to a
| see |
\io\vertx\jphp\ext\web\handler\BodyHandler
for this to be populated. param $encoding [string] the encoding, e.g. "UTF-16" getBodyAsString($encoding) |
|---|
string
stringthe entire HTTP request body as a string, assuming UTF-8 encoding. The context must have first been routed to a {@link io.vertx.ext.web.handler.BodyHandler} for this to be populated.
getCookie( $arg0) : \io\vertx\jphp\ext\web\Cookie
mountPoint() : string
stringthe mount point for this router. It will be null for a top level router. For a sub-router it will be the path at which the subrouter was mounted.
next() : void
This method, if called, does not need to be called during the execution of the handler, it can be called some arbitrary time later, if required.
If next is not called for a handler then the handler should make sure it ends the response or no response will be sent.
normalisedPath() : string
The normalised path is where the URI path has been decoded, i.e. any unicode or other illegal URL characters that were encoded in the original URL with `%` will be returned to their original form. E.g. `%20` will revert to a space. Also `+` reverts to a space in a query.
The normalised path will also not contain any `..` character sequences to prevent resources being accessed outside of the permitted area.
It's recommended to always use the normalised path as opposed to if accessing server resources requested by a client.
stringthe normalised path
parsedHeaders() : \io\vertx\jphp\ext\web\ParsedHeaderValues
pathParam( $arg0) : string
string
stringthe actual value of the parameter or null if it doesn't exist
pathParams() : array
arraythe map of named parameters
preferredLanguage() : \io\vertx\jphp\ext\web\LanguageHeader
It is the same action as returning the first element of the acceptable languages.
\io\vertx\jphp\ext\web\LanguageHeaderthe users preferred locale.
preferredLocale() : \io\vertx\jphp\ext\web\Locale
put( $arg0, $arg1) : $this
string
mixed
$thisa reference to this, so the API can be used fluently
queryParam( $arg0) : array
string
arrayThe list of all elements inside query parameter
queryParams() : \io\vertx\jphp\core\MultiMap
remove( $arg0) : mixed
string
mixedthe previous data associated with the key
removeBodyEndHandler( $arg0) : boolean
integer
booleantrue if the handler existed and was removed, false otherwise
removeCookie( $arg0, $arg1 = null) : \io\vertx\jphp\ext\web\Cookie
param $name [string] the name of the cookie removeCookie($name)
Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar. The context must have first been routed to a
| see |
\io\vertx\jphp\ext\web\handler\CookieHandler
for this to work. param $name [string] the name of the cookie param $invalidate [boolean] removeCookie($name, $invalidate) |
|---|
string
boolean
\io\vertx\jphp\ext\web\Cookiethe cookie, if it existed, or null
removeHeadersEndHandler( $arg0) : boolean
integer
booleantrue if the handler existed and was removed, false otherwise
request() : \io\vertx\jphp\core\http\HttpServerRequest
reroute( $arg0, $arg1 = null) : void
param $path [string] the new http path. reroute($path)
Restarts the current router with a new method and path. All path parameters are then parsed and available on the params list.
param $method [string] the new http request param $path [string] the new http path. reroute($method, $path)
string
string
response() : \io\vertx\jphp\core\http\HttpServerResponse
session() : \io\vertx\jphp\ext\web\Session
Sessions live for a browser session, and are maintained by session cookies.
\io\vertx\jphp\ext\web\Sessionthe session.
setAcceptableContentType( $arg0) : void
string
setBody( $arg0) : void
Buffer
setSession( $arg0) : void
Session
setUser( $arg0) : void
User
statusCode() : integer
| see |
\io\vertx\jphp\ext\web\RoutingContext::fail
then this will return that status code. It can be used by failure handlers to render a response, e.g. create a failure response page. When the status code has not been set yet (it is undefined) its value will be -1. |
|---|---|
integerthe status code used when signalling failure
user() : \io\vertx\jphp\ext\auth\User
vertx() : \io\vertx\jphp\core\Vertx
\io\vertx\jphp\core\Vertxthe Vert.x instance associated to the initiating {@link Router} for this context