Download the PHP package phpraptor/request without Composer
On this page you can find all versions of the php package phpraptor/request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpraptor/request
More information about phpraptor/request
Files in phpraptor/request
Package request
Short Description Light weight class to wrap the incoming request in one single object.
License MIT
Homepage https://github.com/phpraptor/request
Informations about the package request
Introduction
Raptor Request is a light weight PHP library built using the SOLID principles to wrap the incoming HTTP request in one single object, with a structure based on [RFC7230].
To install the library , just run the following composer command.
To capture the request, simply create an object of the Http
class.
As stated in Section 3 of the [RFC7230],
All HTTP/1.1 messages consist of a start-line followed by a sequence of octets in a format similar to the Internet Message Format [RFC5322]: zero or more header fields (collectively referred to as the "headers" or the "header section"), an empty line indicating the end of the header section, and an optional message body.
HTTP-message = start-line *( header-field CRLF ) CRLF [ message-body ]
Or, in simple words, a request message has three components, a request-line
(according to Section 3.1 of the [RFC7230], for a request message the start-line
will be a request-line
), followed by header-fields
and then a message-body
.
You can access these three components by calling line()
, header()
and body()
methods on the request object.
Request-line
Section 3.1.1 of the [RFC7230] states,
A request-line begins with a method token, followed by a single space (SP), the request-target, another single space (SP), the protocol version, and ends with CRLF.
request-line = method SP request-target SP HTTP-version CRLF
This means that the request-line itself is further divided into three sub-components.
Method token
To get the method token or the request method, call the method()
function.
Request-target
Section 5.3 of the [RFC7230] states,
There are four distinct formats for the request-target, depending on both the method being requested and whether the request is to a proxy.
request-target = origin-form / absolute-form / authority-form / asterisk-form
According to Section 3.1.1 of the [RFC7230],
The most common form of request-target is the origin-form.
origin-form = absolute-path [ "?" query ]
The origin-form
has two sub-components, the absolute-path
and the query string parameters
.
-
Absolute-path (Request URI)
To get the absolute path or the request URI, call the
path()
method. -
Query String Parameters ($_GET)
To get all the query string parameters, call the
query()
method.
If you want to get a particular query string parameter, call the query()
method and pass the required key as the argument.
You can also define a default value to return if a key does not exist in the query string parameters.
HTTP-version
To get the HTTP-version, call the version()
method.
Header Fields
To get all the header fields or the request headers, call the all()
method on the header()
method of the request object.
If you want to get a particular header field, call the get()
method and pass the required key as the argument.
You can also define a default value to return if a key does not exist in the header fields.
Cookies ($_COOKIE)
The browser cookies are sent to the server with the header fields, so to get all the cookies, call the cookie()
method on the header()
method of the request object.
If you want to get a particular cookie, call the cookie()
method and pass the required key as the argument.
You can also define a default value to return if a key does not exist in the cookies.
Message Body
Section 3.3 of the [RFC7230] states,
The message body (if any) of an HTTP message is used to carry the payload body of that request
The payload body can contain request body parameters, i.e. $_POST
, and any uploaded files, i.e. $_FILES
.
Request Body Parameters ($_POST)
To get all the request body parameters, call the param()
method.
If you want get a particular request body parameter, call the param()
method and pass the required key as the argument.
You can also define a default value to return if a key does not exist in the request body parameters.
Uploaded Files ($_FILE)
To get all the uploaded files, call the files()
method.
If you want get a particular uploaded file, call the file()
method and pass the required key as the argument.
Content Length
To get the content length of the message body, call the contentLength()
method.
Content Type
To get the content type of the message body, call the contentType()
method.