Skip to main content

Overview

The InjectRequestParams 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

The above injects three parameters:
  • scenario = "assign" (string)
  • mode = "REVOKE" (string)
  • dry_run = true (boolean)

Parameters

The middleware accepts variable arguments in the format key=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.key
boolean
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 with json: to decode JSON:

Base64-Encoded Values

Prefix with b64: 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