-
-
Notifications
You must be signed in to change notification settings - Fork 3
Constructing the Input class
Greg Bowler edited this page Apr 25, 2024
·
6 revisions
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.
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.
PHP.Gt/Input is a separately maintained component of PHP.Gt/WebEngine.