# Request

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:

Route::get('/', function($request) {
});

Route::code(404, function($request) {
});

Middleware:

Middleware::before('/', function($request) {
});

Controller:

namespace Controller;

class Home extends Controller
{
    public function index($request)
    {
    }
}

General methods

Get parameter

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.

Has parameter

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.

Get body parameter

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 body parameter

has(string $key)

Returns true if the given body parameter key exists, false otherwise.

$request->has('username');

Get file

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.

Has file

hasFile(string $key)

Returns true if the given file key exists, false otherwise.

$request->hasFile('profile_image');

File options

fileOptions(array $arr)

Defines the options for uploading the request files, explained more in the file page of this documentation.

Get cookie

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.

Has cookie

hasCookie(string $key)

Returns true if the given cookie key exists, false otherwise.

$request->hasCookie('user_session');

Get header

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.

Get method

getMethod()

Returns the HTTP method.

$request->getMethod();

In a request of type post it will return POST.

Get Url

getUri()

Returns the request uri (without the query).

$request->getUri();

Get full Url

getFullUri()

Returns the full request uri.

$request->getUri();

Is secure

isSecure()

Returns true if the current request protocol is secure (HTTPS), false otherwise.

$request->isSecure();
Documentation made with
Something is wrong in here? Make a issue/pull request on the repo.