Overview
TheInjectRequestParams middleware allows you to inject static or dynamic parameters directly into the request from route definitions. It supports intelligent type casting including booleans, nulls, numbers, JSON, and base64-encoded payloads.
Basic Usage
scenario="assign"(string)mode="REVOKE"(string)dry_run=true(boolean)
Parameters
The middleware accepts variable arguments in the formatkey=value or key:value:
string
Key-value pairs to inject. Supports both
= and : as separators.Options
Leading parameters modify the injection behavior:string
Namespace prefix for all injected keys. Example:
ns=_meta injects keys as _meta.keyboolean
default:"false"
When
true, overwrites existing request values. By default, only sets values if not already present.Value Casting
The middleware automatically casts string values to appropriate PHP types:Boolean Values
Null Values
Numeric Values
JSON Objects and Arrays
Prefix withjson: to decode JSON:
Base64-Encoded Values
Prefix withb64: to decode base64. If the decoded content looks like JSON, it’s automatically decoded:
Plain Strings
Any value that doesn’t match special patterns is kept as a string:Advanced Usage
Namespace Prefixing
Group injected parameters under a namespace:Force Overwrite
Overwrite existing request values:Combined Options
Use Cases
Scenario-Based Processing
Audit Metadata
Feature Flags
Default Values
Request Attributes
Injected values are also stored as request attributes (not just input), making them accessible via:Type Casting Reference
Examples
Complex JSON Injection
Multiple Middleware Instances
See Also
- FilterRequestByRole Middleware - Role-based field filtering
- TransformData Middleware - Request validation