Constructing the Input class - PhpGt/Input GitHub Wiki

The Input class is the main entrypoint to the functionality of this library. It is a representation of the $_GET, $_POST, and $_FILES superglobals, and the php://input stream.

Construct the class as follows (the 4th parameter is optional, defaulting to "php://input"):

use Gt\Input\Input;

$input = new Input($_GET, $_POST, $_FILES);

All functionality can be accessed from a constructed Input class.

Usage within WebEngine applications

WebEngine automatically instantiates the Input class and stores it in the Service Container. This allows the developer to access the pre-constructed Input class from within any [go or do function][webengine-go-do], like this:

use Gt\Input\Input;

function do_save(Input $input, DataStorage $data):void {
	$name = $input->getString("name");
	$data->storeName($name);
}

In the next page, learn about using the type-safe getters.