PHPackages                             initphp/input - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. initphp/input

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

initphp/input
=============

Read and validate GET, POST and JSON body input with configurable source priority for PHP.

2.0.0(3w ago)112311MITPHPPHP &gt;=8.1CI passing

Since Jul 25Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Input)[ Packagist](https://packagist.org/packages/initphp/input)[ RSS](/packages/initphp-input/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (7)Versions (4)Used By (1)

InitPHP Input
=============

[](#initphp-input)

Read 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 small API.

[![Latest Stable Version](https://camo.githubusercontent.com/d95c021388c3766064ca280e52ae4ca55e4bc7ddab0aa5195aa25a5df35be9f2/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f696e7075742f76)](https://packagist.org/packages/initphp/input)[![Total Downloads](https://camo.githubusercontent.com/afc9b77cc9b712914b7ed5c5bde5a50519af4274f174403c9d2d71fbd59161e5/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f696e7075742f646f776e6c6f616473)](https://packagist.org/packages/initphp/input)[![CI](https://github.com/InitPHP/Input/actions/workflows/ci.yml/badge.svg)](https://github.com/InitPHP/Input/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/58f848b64032c576a06b148ec1af1c110b600712e4d7d1c04e6349baf95d444d/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f696e7075742f6c6963656e7365)](https://packagist.org/packages/initphp/input)[![PHP Version Require](https://camo.githubusercontent.com/08c14d983f8448d2d1d429808f5629917e4d981275483e9873b45c4326216a09/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f696e7075742f726571756972652f706870)](https://packagist.org/packages/initphp/input)

---

Features
--------

[](#features)

- Three input sources behind one API: `get` (`$_GET`), `post` (`$_POST`) and `raw` (the decoded JSON `php://input` body).
- Twelve priority helpers (`getPost`, `postRawGet`, …) that read the sources in a defined order — **the first source that contains the key wins**.
- Per-call validation powered by [initphp/validation](https://github.com/InitPHP/Validation): a value that fails its rules yields the default.
- A safe JSON body reader: a scalar or malformed payload becomes an empty set instead of a fatal error.
- A static facade for ergonomic access, plus a fully injectable instance for testing and dependency injection.
- No shared static state between instances; PHPStan level max clean.

Requirements
------------

[](#requirements)

- PHP 8.1 or later
- [initphp/parameterbag](https://github.com/InitPHP/ParameterBag) `^2.0`
- [initphp/validation](https://github.com/InitPHP/Validation) `^2.0`
- `ext-json`

Installation
------------

[](#installation)

```
composer require initphp/input
```

Quick start
-----------

[](#quick-start)

### With the facade

[](#with-the-facade)

```
require_once 'vendor/autoload.php';

use InitPHP\Input\Facade\Inputs as Input;

// GET /?name=Jane
// echo isset($_GET['name']) ? $_GET['name'] : 'John';
echo Input::get('name', 'John'); // 'Jane'
```

### With an instance

[](#with-an-instance)

```
use InitPHP\Input\Inputs;

$input = new Inputs(); // reads $_GET, $_POST and php://input

$name = $input->get('name', 'John');
```

You can also hand the sources in explicitly — handy in tests or when the data does not come from the superglobals:

```
$input = new Inputs(
    get: ['name' => 'Jane'],
    post: ['email' => 'jane@example.com'],
    raw: ['token' => 'abc123'],
);
```

Reading from a single source
----------------------------

[](#reading-from-a-single-source)

```
$input->get('name', 'guest');   // from $_GET
$input->post('email');          // from $_POST
$input->raw('token');           // from the JSON request body
```

Each accessor returns the default (second argument, `null` when omitted) if the key is absent. Keys are matched **case-sensitively**, just like real HTTP query and body parameters.

Source priority
---------------

[](#source-priority)

The priority helpers walk their sources in the order their name reads, left to right, and return the value of the **first source that contains the key**:

```
// GET /?year=1999  (no POST, no body)
$input->getPost('year', 2015); // 1999 — taken from $_GET

// POST year=1999  (no GET)
$input->getPost('year', 2015); // 1999 — fell through to $_POST
```

The full set: `getPost`, `getRaw`, `getPostRaw`, `getRawPost`, `postGet`, `postRaw`, `postGetRaw`, `postRawGet`, `rawGet`, `rawPost`, `rawGetPost`, `rawPostGet`.

Validation
----------

[](#validation)

Pass a list of [validation rules](https://github.com/InitPHP/Validation)as the third argument. When the resolved value fails, the default is returned:

```
// if year is present and within 1970–2070 use it, otherwise 2015
$year = $input->getPost('year', 2015, ['range(1970...2070)']);

// required + must equal the password_retype field
$password = $input->post('password', null, ['required', 'again(password_retype)']);
```

> The first source that **owns** the key is the one validated; a present but invalid value returns the default and does **not** fall through to the next source.

Presence checks
---------------

[](#presence-checks)

```
$input->hasGet('name');  // isset($_GET['name']) — case-sensitive
$input->hasPost('email');
$input->hasRaw('token');
```

Documentation
-------------

[](#documentation)

Full developer documentation lives in [`docs/`](docs/README.md): getting started, each source, the priority model, validation, the facade, a complete API reference and an FAQ.

Testing
-------

[](#testing)

```
composer test       # PHPUnit
composer stan       # PHPStan (level max)
composer cs-check   # PHP-CS-Fixer (dry-run)
composer ci         # all of the above
```

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Released under the [MIT License](./LICENSE).

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance95

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~707 days

Total

3

Last Release

24d ago

Major Versions

1.2 → 2.0.02026-06-10

PHP version history (2 changes)1.1PHP &gt;=7.2

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (7 commits)")

---

Tags

getinitphpinputinput-validationjson-bodyphppostrequestvalidationrequestphpvalidationinputgetpostjson bodyinitphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/initphp-input/health.svg)

```
[![Health](https://phpackages.com/badges/initphp-input/health.svg)](https://phpackages.com/packages/initphp-input)
```

###  Alternatives

[arondeparon/laravel-request-sanitizer

An easy to use request sanitizer that allows you to sanitize your form data before validating it.

112160.9k4](/packages/arondeparon-laravel-request-sanitizer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
