Skip to content
Muhammet Şafak edited this page Jun 10, 2026 · 2 revisions

InitPHP Input — Wiki

Welcome to the official documentation for initphp/input — a small, focused library for reading a single request value from the query string, the submitted form fields, or the JSON request body, with configurable source priority and optional validation, behind one tidy API.

Built for PHP 8.1+.

composer require initphp/input
use InitPHP\Input\Facade\Inputs as Input;

// GET /?page=2
$page  = Input::get('page', 1);                          // '2'
$year  = Input::getPost('year', 2015, ['range(1970...2070)']);
$token = Input::raw('token');                            // from the JSON body

The package in one table

Symbol Role
Inputs The implementation. Wraps the three sources and reads values from them.
InputInterface The contract every accessor implements — type-hint this in your services.
Facade\Inputs A static proxy over a single Inputs instance: Input::get(...).
Inputs::decodeJsonBody() Safely turn a raw JSON body into an input array (scalars/garbage become []).

Start here

What you get

  • Three sources behind one API. get ($_GET), post ($_POST) and raw (the decoded JSON php://input body). See Reading Sources.
  • Twelve priority helpers. getPost, postRawGet, rawGetPost, … read the sources in a defined order and return the first one that contains the key. See Source Priority.
  • Per-call validation. Hand a list of rules to any accessor; a value that fails yields the default. Powered by initphp/validation. See Validation.
  • A safe JSON body reader. A scalar or malformed body decodes to an empty set instead of a fatal error.
  • A facade and an injectable instance. Use Input::get(...) for app code, or new Inputs(...) with explicit data for tests and DI. See The Facade and Testing.
  • No shared static state. Two Inputs objects never interfere; PHPStan level max clean; 100% test coverage.

The three sources at a glance

Source Backed by Accessor Presence check
get $_GET get() hasGet()
post $_POST post() hasPost()
raw php://input* raw() hasRaw()

* The body is read once and JSON-decoded. Only a JSON object/array becomes data; anything else is treated as empty.

Package metadata

If something in this wiki is unclear, wrong, or out of date, open an issue — documentation fixes are merged eagerly.

Clone this wiki locally