Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
API Reference
Every public symbol in the package. Unless noted, the shared accessor signature is:
function (string$key, mixed$default = null, ?array$validation = null): mixed$key— the parameter name (case-sensitive).$default— returned when the key is absent or the value fails validation. Defaults tonull.$validation— a list of validation rules (DSL strings and/or callables). Empty ornullskips validation.
InitPHP\Input\InputInterface — the contract implemented by Inputs.
Type-hint this in your services for dependency injection.
| Method | Reads from |
|---|---|
get() | $_GET |
post() | $_POST |
raw() | decoded JSON php://input body |
| Method | Order |
|---|---|
getPost() | get → post |
getRaw() | get → raw |
getPostRaw() | get → post → raw |
getRawPost() | get → raw → post |
postGet() | post → get |
postRaw() | post → raw |
postGetRaw() | post → get → raw |
postRawGet() | post → raw → get |
rawGet() | raw → get |
rawPost() | raw → post |
rawGetPost() | raw → get → post |
rawPostGet() | raw → post → get |
| Method | Returns |
|---|---|
hasGet(string $key): bool | whether $key exists in $_GET |
hasPost(string $key): bool | whether $key exists in $_POST |
hasRaw(string $key): bool | whether $key exists in the body |
A key whose stored value is null still counts as present.
InitPHP\Input\Inputs — final, implements InputInterface.
publicfunction __construct(
?array$get = null,
?array$post = null,
?array$raw = null,
?\InitPHP\Validation\Validation$validation = null
)Builds an instance over the three sources. Each null argument falls back
to its global:
| Argument | Falls back to |
|---|---|
$get | $_GET |
$post | $_POST |
$raw | the decoded php://input body |
$validation | a fresh Validation instance |
The argument names are part of the public API — named arguments such as
new Inputs(get: [...], raw: [...]) are supported and encouraged.
$input = newInputs(
get: ['name' => 'Jane'],
post: ['email' => 'jane@example.com'],
raw: ['token' => 'abc123'],
);publicstaticfunction decodeJsonBody(string$body): arrayJSON-decode a raw request body into an input array. An empty string, a
scalar (5, "x", true), or malformed JSON returns [], so a scalar
payload can never reach the underlying container.
Inputs::decodeJsonBody('{"a":1}'); // ['a' => 1]
Inputs::decodeJsonBody('42'); // []
Inputs::decodeJsonBody('oops'); // []
Inputs::decodeJsonBody(''); // []InitPHP\Input\Facade\Inputs — final. A static proxy over a single
InputInterface instance; all InputInterface methods are callable
statically (e.g. Inputs::get(...)).
| Method | Description |
|---|---|
setInstance(InputInterface $instance): void | Replace the backing instance (tests, DI). |
reset(): void | Forget the backing instance; the next call rebuilds it. |
See The Facade.
- Case sensitivity. Keys are matched exactly;
nameandNamediffer. - Value types. Values are returned as the source provides them — query/form values are strings, JSON-body values keep their decoded type.
- Flat storage. Each source is a flat bag; a dotted key is a literal key, not a path into nested data.
- No fall-through on invalid. In a priority helper, the first source that has the key is committed to; an invalid value returns the default rather than trying the next source.
- Isolation. Instances share no static state; two
Inputsobjects never interfere.
initphp/input · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy