Oihana PHP System

GetParamTrait uses trait:short

Provides flexible access to request parameters from query strings and request bodies.

Supports dot notation for nested keys (e.g., 'geo.latitude', 'address.postalCode').

It provides methods to:

  • Get single parameters (getParam, getBodyParam, getQueryParam)
  • Get multiple parameters at once (getBodyParams, getParams)
  • Get typed parameters with optional range validation (getParamInt, getParamFloat, etc.)
  • Fetch default values from a model if the parameter is not present (getParamDefaultValueInModel)

Usage example:

$name = $this->getBodyParam($request, 'name');          // simple key
$lat  = $this->getBodyParam($request, 'geo.latitude'); // nested key
$data = $this->getBodyParams($request, ['name', 'geo.latitude']);

Table of Contents

Properties

$container  : Container
The DI container reference.
$paramsStrategy  : string
Strategy to fetch parameters: 'both' (default), 'body' only, or 'query' only.

Methods

getBodyParam()  : mixed|null
Get a single parameter from the request body.
getBodyParams()  : array<string|int, mixed>|null
Get multiple parameters from the request body.
getParam()  : mixed
Get a single parameter from query or body according to the current strategy.
getParams()  : array<string|int, mixed>|null
Get all query parameters or body parameters if query is empty.
getQueryParam()  : string|null
Get a single parameter from query string.
initializeParamsStrategy()  : static
Initialize the params strategy : 'both' (default), 'body' (only), 'query' (only).
getParamArray()  : array<string|int, mixed>|null
Get an array parameter from request.
getParamBool()  : bool|null
Get a boolean parameter from request.
getParamDefaultValueInModel()  : mixed
Generates the status property from the current Request or find it in the status model with the default label ('on' by default).
getParamFloat()  : float|null
Get a float parameter.
getParamFloatWithRange()  : float|null
getParamInt()  : int|null
Get an integer parameter.
getParamIntWithRange()  : int|null
getParamNumberWithRange()  : mixed
Get a numeric parameter with a min/max range validation.
getParamString()  : string|null

Properties

$container

The DI container reference.

public Container $container

$paramsStrategy

Strategy to fetch parameters: 'both' (default), 'body' only, or 'query' only.

public string $paramsStrategy = \oihana\enums\http\HttpParamStrategy::BOTH

Methods

getBodyParam()

Get a single parameter from the request body.

public getBodyParam(ServerRequestInterface|null $request, string $name) : mixed|null

Supports dot notation for nested values.

Parameters
$request : ServerRequestInterface|null
$name : string

Parameter key, can be nested ('geo.latitude').

Return values
mixed|null

getBodyParams()

Get multiple parameters from the request body.

public getBodyParams(ServerRequestInterface|null $request, array<string|int, string> $names) : array<string|int, mixed>|null

Only keys present in the body are returned, nested keys supported.

Parameters
$request : ServerRequestInterface|null
$names : array<string|int, string>

Array of keys to retrieve, can use dot notation.

Return values
array<string|int, mixed>|null

Associative array of key => value.

getParam()

Get a single parameter from query or body according to the current strategy.

public getParam(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $default = [] ][, bool $throwable = false ]) : mixed

Supports dot notation for nested keys.

Parameters
$request : ServerRequestInterface|null
$name : string

Parameter key

$default : array<string|int, mixed> = []

Default array to look up the value if not found

$throwable : bool = false

If true, throws NotFoundException when parameter is not found

Tags
throws
NotFoundException

getParams()

Get all query parameters or body parameters if query is empty.

public getParams(ServerRequestInterface|null $request) : array<string|int, mixed>|null
Parameters
$request : ServerRequestInterface|null
Return values
array<string|int, mixed>|null

getQueryParam()

Get a single parameter from query string.

public getQueryParam(ServerRequestInterface|null $request, string $name) : string|null

Supports dot notation for nested keys.

Parameters
$request : ServerRequestInterface|null
$name : string
Return values
string|null

initializeParamsStrategy()

Initialize the params strategy : 'both' (default), 'body' (only), 'query' (only).

public initializeParamsStrategy([string|array<string|int, mixed>|null $strategy = null ]) : static
Parameters
$strategy : string|array<string|int, mixed>|null = null

$strategy Either a string strategy or an array with key ControllerParam::PARAMS_STRATEGY.

Tags
see
getParam

The params strategy is used in the getParam() method.

Return values
static

getParamArray()

Get an array parameter from request.

protected getParamArray(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null $defaultValue = null ][, bool $throwable = false ]) : array<string|int, mixed>|null

Returns null if not found and defaultValue is not set.

Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []
$defaultValue : array<string|int, mixed>|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
array<string|int, mixed>|null

getParamBool()

Get a boolean parameter from request.

protected getParamBool(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, bool|null $defaultValue = null ][, bool $throwable = false ]) : bool|null

Returns null if not found and defaultValue is not set.

Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []

Additional arguments (ignored)

$defaultValue : bool|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
bool|null

getParamDefaultValueInModel()

Generates the status property from the current Request or find it in the status model with the default label ('on' by default).

protected getParamDefaultValueInModel(ServerRequestInterface|null $request, string $name, null|string|GetModel $model[, string|null $key = null ][, string|null $value = null ][, string $fields = Prop::_KEY ][, string $property = Prop::_KEY ][, bool $throwable = false ]) : mixed
Parameters
$request : ServerRequestInterface|null
$name : string

The name of the parameter.

$model : null|string|GetModel

The identifier of the model.

$key : string|null = null

The key in the collection to target to find the default value.

$value : string|null = null

The value to search in the model to returns the good key.

$fields : string = Prop::_KEY
$property : string = Prop::_KEY

The name of the property to extract in the model result.

$throwable : bool = false
Tags
throws
DependencyException
throws
NotFoundException

getParamFloat()

Get a float parameter.

protected getParamFloat(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, float|null $defaultValue = null ][, bool $throwable = false ]) : float|null
Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []
$defaultValue : float|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
float|null

getParamFloatWithRange()

protected getParamFloatWithRange(ServerRequestInterface|null $request, string $name, float $min, float $max[, mixed $defaultValue = null ][, array<string|int, mixed> $args = [] ][, bool $throwable = false ]) : float|null
Parameters
$request : ServerRequestInterface|null
$name : string
$min : float
$max : float
$defaultValue : mixed = null
$args : array<string|int, mixed> = []
$throwable : bool = false
Tags
throws
NotFoundException
Return values
float|null

getParamInt()

Get an integer parameter.

protected getParamInt(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, int|null $defaultValue = null ][, bool $throwable = false ]) : int|null
Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []
$defaultValue : int|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
int|null

getParamIntWithRange()

protected getParamIntWithRange(ServerRequestInterface|null $request, string $name, int $min, int $max[, mixed $defaultValue = null ][, array<string|int, mixed> $args = [] ][, bool $throwable = false ]) : int|null
Parameters
$request : ServerRequestInterface|null
$name : string
$min : int
$max : int
$defaultValue : mixed = null
$args : array<string|int, mixed> = []
$throwable : bool = false
Tags
throws
NotFoundException
Return values
int|null

getParamNumberWithRange()

Get a numeric parameter with a min/max range validation.

protected getParamNumberWithRange(ServerRequestInterface|null $request, string $name, int $filter, int $min, int $max[, int|float|null $defaultValue = null ][, array<string|int, mixed> $args = [] ][, string $strategy = HttpParamStrategy::BOTH ][, bool $throwable = false ]) : mixed
Parameters
$request : ServerRequestInterface|null
$name : string
$filter : int

FILTER_VALIDATE_INT or FILTER_VALIDATE_FLOAT

$min : int
$max : int
$defaultValue : int|float|null = null
$args : array<string|int, mixed> = []
$strategy : string = HttpParamStrategy::BOTH
$throwable : bool = false
Tags
throws
NotFoundException

getParamString()

protected getParamString(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, string|null $defaultValue = null ][, bool $throwable = false ]) : string|null
Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []
$defaultValue : string|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
string|null

        
On this page

Search results