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)
{
}
}
query([string $key])
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)
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])
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)
Returns true if the given body parameter key exists, false otherwise.
$request->has('username');
file([string $key])
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)
Returns true if the given file key exists, false otherwise.
$request->hasFile('profile_image');
fileOptions(array $arr)
Defines the options for uploading the request files, explained more in the file page of this documentation.
cookie([string $key])
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)
Returns true if the given cookie key exists, false otherwise.
$request->hasCookie('user_session');
getHeader([string $key])
Returns the specified request header.
$request->getHeader('Content-type');
If no parameter is passed, it will return an array with all the headers.
getMethod()
Returns the HTTP method.
$request->getMethod();
In a request of type post it will return POST.
getUri()
Returns the request uri (without the query).
$request->getUri();
getFullUri()
Returns the full request uri.
$request->getUri();
isSecure()
Returns true if the current request protocol is secure (HTTPS), false otherwise.
$request->isSecure();