-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Muhammet Şafak edited this page Jun 10, 2026
·
2 revisions
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/inputuse 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| 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 []). |
- New to the package? Read Installation, then Quick Start.
-
Reading one source? Reading Sources covers
get,postandraw. - Value might be in several places? Source Priority explains the twelve priority helpers and the first source that has the key wins rule.
- Want to reject bad input? Validation.
- Prefer static calls? The Facade.
- Coming from 1.x? Read Migration from 1.x — 2.0 is a breaking release.
-
Three sources behind one API.
get($_GET),post($_POST) andraw(the decoded JSONphp://inputbody). 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, ornew Inputs(...)with explicit data for tests and DI. See The Facade and Testing. -
No shared static state. Two
Inputsobjects never interfere; PHPStan level max clean; 100% test coverage.
| 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.
- License: MIT
- Minimum PHP: 8.1
-
Required extensions:
ext-json -
Runtime dependencies:
initphp/parameterbag ^2.0,initphp/validation ^2.0 -
Packagist:
initphp/input - Source: github.com/InitPHP/Input
- Issues: github.com/InitPHP/Input/issues
- Discussions: github.com/orgs/InitPHP/discussions
If something in this wiki is unclear, wrong, or out of date, open an issue — documentation fixes are merged eagerly.
initphp/input · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Usage
Reference
Other