-
-
Notifications
You must be signed in to change notification settings - Fork 1
Migration from 1.x
Version 2.0 is a breaking release. It raises the PHP floor, moves to the 2.0 line of its dependencies, and fixes long-standing correctness issues in the way state was shared. Most application code that used the facade keeps working unchanged; the breaking changes mostly affect edge cases and direct instantiation.
| Area | 1.x | 2.0 |
|---|---|---|
| Minimum PHP | 7.2 | 8.1 |
initphp/parameterbag |
^1.1 |
^2.0 |
initphp/validation |
^1.0 |
^2.0 |
| Key matching | case-insensitive | case-sensitive |
| Instance state | shared static bags |
per-instance, isolated |
| Destructor |
__destruct cleared shared bags |
removed |
Facade instance __call
|
present | removed (__callStatic only) |
New: InputInterface
|
— | added |
| New: constructor injection | — | new Inputs(get:…, post:…, raw:…) |
New: Inputs::decodeJsonBody()
|
— | added |
New: Facade::setInstance() / reset()
|
— | added |
Version 2.0 requires PHP 8.1+ because initphp/validation ^2.0 does.
Update your environment, then:
composer require initphp/input:^2.01.x folded every key to lower-case, so get('Name') and get('name') were
the same key. 2.0 matches keys exactly, mirroring how HTTP query and
body parameters actually behave.
$input = new Inputs(get: ['Name' => 'Jane']);
$input->get('Name'); // 'Jane'
$input->get('name'); // null (1.x would have returned 'Jane')If you relied on the old behaviour, normalise the key yourself before calling:
$input->get(strtolower($key));In 1.x the three source bags were static and a destructor cleared them,
which meant a second Inputs instance — or a temporary one being garbage
collected — could silently empty the data for everyone.
2.0 stores state per instance. Each Inputs is independent, and the
destructor is gone. This is the bug fix you most likely want, but if any of
your code depended on two Inputs objects sharing data through statics,
that no longer happens — give them the same data explicitly, or use the
facade, which holds a single shared instance.
The facade is still used exactly the same way:
use InitPHP\Input\Facade\Inputs as Input;
Input::get('name', 'John'); // unchangedWhat changed:
- The unused instance-level
__callwas removed; only the static__callStaticproxy remains. (Calling facade methods on an instance of the facade was never the intended usage.) - New
Input::setInstance(...)andInput::reset()let you inject a configured instance — see The Facade and Testing.
Validation moved to 2.0 as well. The rules used by this package's examples —
required, range(...), again(...), integer, mail, … — still exist
and behave the same. If you used more exotic rules, check the Validation
wiki's
Rules Reference
and Migration from 1.x.
-
InputInterface— type-hint it in your services instead of the concrete class (see Recipes). -
Constructor injection —
new Inputs(get: [...], post: [...], raw: [...])for tests and custom request abstractions. -
Inputs::decodeJsonBody()— a safe, reusable JSON-body decoder.
- PHP runtime is 8.1+
-
composer require initphp/input:^2.0 - Audit any case-sensitive key lookups
- Remove any code that relied on static cross-instance state
- (Optional) switch service type-hints to
InputInterface
initphp/input · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Usage
Reference
Other