Download the PHP package marcosfermin/http without Composer
On this page you can find all versions of the php package marcosfermin/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marcosfermin/http
More information about marcosfermin/http
Files in marcosfermin/http
Informations about the package http
Http Component
Installation
You can use composer to install this component. The package is:
Basic Usage
Request
The Request class provides an object oriented wrapper around the PHP superglobals. This makes it possible to inject it as a dependency into any of your classes that require it.
Now you can use the following methods on the $request
object:
Please note that both GET and POST parameters are merged together and accessible with getParameter
.
Response
The HttpResponse
object is the data holder for the HTTP response. It has no constructor dependencies and can be instantiated with just:
The response can be modified with following methods:
If you don't supply a status text with setStatusCode
then an appropriate default status text will be selected for the HTTP status code if available.
addHeader
adds a new header value without overwriting existing values, setHeader
will overwrite an existing value.
The redirect
method will set the status code and text for a 301 redirect.
deleteCookie
will set the cookie content to nothing and put the expiration in the past.
The following two methods are available to send the response to the client:
They can be used like this:
The second parameter of header
must be false. Otherwise existing headers will be overwritten.
Cookies
To avoid new
calls in your classes and to have the ability to set default cookie settings for you application, there is a CookieBuilder
class that you can use to create your cookie objects. It has the following methods available:
You can use the following methods to manipulate an existing cookie:
The cookie object can the be used with the HttpResponse
methods addCookie
and deleteCookie
.