Wolff\Core\Http\Request
Wolff offers you a quite useful and complete request object. It implements the Wolff\Core\Http\RequestInterface
interface.
This can be done to avoid the superglobals of PHP, giving you a more object oriented syntax.
This request object is the one that must be passed as parameter to the Controller's public functions, route functions, and middleware functions.
Route::get('/', function($request) {
});
Route::code(404, function($request) {
});
Middleware::before('/', function($request) {
});
namespace Controller;
class Home extends Controller
{
public function index($request)
{
// Code
}
}
query([string $key]): mixed
Returns the requested parameter (usually available in the $_GET
superglobal array).
Given the route localhost/wolff?foo=bar
.
$request->query('foo');
It will return bar
.
If no parameter is passed, it will return an array with all the parameters.
hasQuery(string $key): bool
Returns true
if the given parameter key exists, false
otherwise.
$request->hasQuery('foo');
Given the route localhost/wolff?foo=bar
it should return true
.
body([string $key]): mixed
Returns the specified body parameter (usually available in the $_POST
superglobal array).
$request->body('username');
If no parameter is passed, it will return an array with all the body parameters.
has(string $key): bool
Returns true
if the given body parameter key exists, false
otherwise.
$request->has('username');
file([string $key]): mixed
Returns the specified file (usually available in the $_FILE
superglobal array).
$request->file('profile')
Keep in mind that these files are an instance of Wolff\Core\Http\File
(builded on top of the $_FILE
array). You can look at the File
page of this documentation for more information.
If no parameter is passed, it will return an array with all the files.
hasFile(string $key): bool
Returns true
if the given file key exists, false
otherwise.
$request->hasFile('profile_image');
fileOptions(array $arr): void
Defines the options for uploading the request files, explained more in the file page of this documentation.
cookie([string $key]): mixed
Returns the specified cookie (usually available in the $_COOKIE
superglobal array).
$request->cookie('user_session');
If no parameter is passed, it will return an array with all the cookies.
hasCookie(string $key): bool
Returns true
if the given cookie key exists, false
otherwise.
$request->hasCookie('user_session');
getHeader([string $key]): mixed
Returns the specified request header.
$request->getHeader('Content-type');
If no parameter is passed, it will return an array with all the headers.
getMethod(): string
Returns the HTTP method.
$request->getMethod();
In a request of type post it will return POST
.
getUri(): string
Returns the request uri (without the query).
$request->getUri();
getFullUri(): string
Returns the full request uri.
$request->getUri();
isSecure(): bool
Returns true
if the current request protocol is secure (HTTPS), false
otherwise.
$request->isSecure();