Oihana PHP System

getParamIntRange.php

Table of Contents

Functions

getParamIntRange()  : int|null
Retrieves an integer parameter from the request and clamps it within a given range.

Functions

getParamIntRange()

Retrieves an integer parameter from the request and clamps it within a given range.

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

Wrapper around getParamNumberRange() that ensures integer return type.

Parameters
$request : ServerRequestInterface|null

The PSR-7 server request instance. Can be null.

$name : string

The parameter name or dot-notated path.

$min : int

Minimum allowed integer value.

$max : int

Maximum allowed integer value.

$defaultValue : int|null = null

Value returned if the parameter is missing or not numeric. Default null.

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

Optional defaults passed to getParam().

$strategy : string = HttpParamStrategy::BOTH

Which source to search: HttpParamStrategy::BOTH|QUERY|BODY. Default BOTH.

$throwable : bool = false

Whether to throw NotFoundException if the parameter is missing. Default false.

Tags
throws
NotFoundException

If $throwable is true and the parameter is not found in the request.

example
$quantity = getParamIntRange($request, 'quantity', 1, 10, 5);
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
int|null

The integer value clamped to [$min, $max], or $defaultValue/null if missing or invalid.


        
On this page

Search results