Oihana PHP System

PrepareParamTrait uses trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short

Table of Contents

Properties

$hasTotal  : bool
Indicates if the list method return the total number of elements.
$ids  : null|string|array<string|int, mixed>
The default ids representation, a string list with comma separator or an array.
$skinDefault  : string|null
The default skin for the controller.
$skinMethods  : array<string, string>|null
Method-specific skin definitions.
$skins  : array<string|int, string>|null
List of all available skins for the controller.

Methods

initializeHasTotal()  : static
Initialize the hasTotal property with an associative array definition.
prepareHasTotal()  : bool
Prepare and returns the 'hasTotal' value.
initializeIDs()  : void
Initialize all skins properties with an associative array definition.
initializeSkins()  : static
Initialize the skin-related properties from an associative array.
isValidSkin()  : bool
Validate a given skin.
prepareActive()  : bool|null
prepareBench()  : bool
Prepare and returns the 'bench' value.
prepareDate()  : string|null
preparedIDs()  : string|null
Prepares the identifier list representation (by default ids).
prepareFacets()  : array<string|int, mixed>|null
Prepare the facets definitions.
prepareFilter()  : array<string|int, mixed>|null
Prepare a filter parameter.
prepareGroupBy()  : void
prepareInt()  : int|null
Prepare an integer parameter.
prepareInterval()  : void
prepareLang()  : string|null
prepareLimit()  : int
Prepare and returns the 'limit' value.
prepareMargin()  : bool|null
Prepare and returns the 'margin' flag value.
prepareMock()  : bool|null
Prepare and returns the 'mock' value.
prepareOffset()  : int
Prepare and returns the 'offset' value.
prepareOrder()  : void
prepareParamsFacets()  : void
Try to creates the facets definition with the $this->params array definition of the controller.
prepareQuantity()  : int|null
prepareSearch()  : string|null
prepareSkin()  : string|null
Prepare and determine the effective skin for a request or method.
prepareSort()  : string|null
Prepares the sorting parameter based on the given request and arguments.
prepareTimezone()  : void
Prepare the timezone component.

Properties

$hasTotal

Indicates if the list method return the total number of elements.

public bool $hasTotal = true

$ids

The default ids representation, a string list with comma separator or an array.

public null|string|array<string|int, mixed> $ids = null

$skinDefault

The default skin for the controller.

public string|null $skinDefault = null

This skin is used when no specific skin is requested or defined.

$skinMethods

Method-specific skin definitions.

public array<string, string>|null $skinMethods = null

Array format: [ 'methodName' => 'skinName', ... ] Overrides the default skin for specific controller methods.

$skins

List of all available skins for the controller.

public array<string|int, string>|null $skins = null

Used to validate requested skins.

Methods

initializeHasTotal()

Initialize the hasTotal property with an associative array definition.

public initializeHasTotal([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

prepareHasTotal()

Prepare and returns the 'hasTotal' value.

public prepareHasTotal(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
bool

initializeIDs()

Initialize all skins properties with an associative array definition.

protected initializeIDs([array<string|int, mixed> $init = [] ]) : void
Parameters
$init : array<string|int, mixed> = []

initializeSkins()

Initialize the skin-related properties from an associative array.

protected initializeSkins([array<string, mixed> $init = [] ]) : static

Example:

$this->initializeSkins([
    PrepareSkin::SKIN_DEFAULT => 'default',
    PrepareSkin::SKIN_METHODS => ['edit' => 'editor'],
    PrepareSkin::SKINS        => ['default', 'editor', 'compact']
]);
Parameters
$init : array<string, mixed> = []

Associative array of skin definitions.

Return values
static

Returns the current instance for method chaining.

isValidSkin()

Validate a given skin.

protected isValidSkin(string|null $skin) : bool

Checks if the skin is a string and exists in the defined skins list. Converts the skin name to lowercase before validation.

Parameters
$skin : string|null

Skin name to validate.

Return values
bool

True if the skin exists in the available skins list; false otherwise.

prepareActive()

protected prepareActive(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, bool $defaultValue = true ]) : bool|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$defaultValue : bool = true
Return values
bool|null

prepareBench()

Prepare and returns the 'bench' value.

protected prepareBench(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
bool

prepareDate()

protected prepareDate(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, string|null $default = null ][, string $name = Prop::DATE ]) : string|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
$default : string|null = null
$name : string = Prop::DATE
Return values
string|null

preparedIDs()

Prepares the identifier list representation (by default ids).

protected preparedIDs(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = [] ][, string|null $name = ControllerParam::IDS ]) : string|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = []
$name : string|null = ControllerParam::IDS
Return values
string|null

prepareFacets()

Prepare the facets definitions.

protected prepareFacets(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = [] ]) : array<string|int, mixed>|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = []
Return values
array<string|int, mixed>|null

prepareFilter()

Prepare a filter parameter.

protected prepareFilter(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : array<string|int, mixed>|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
array<string|int, mixed>|null

prepareGroupBy()

protected prepareGroupBy(ServerRequestInterface|null $request, array<string|int, mixed>|null &$params, string|null &$groupBy) : void
Parameters
$request : ServerRequestInterface|null
$params : array<string|int, mixed>|null
$groupBy : string|null
Tags
throws
NotFoundException

prepareInt()

Prepare an integer parameter.

protected prepareInt(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int|null $defaultValue = null ][, string|null $name = null ]) : int|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
$defaultValue : int|null = null
$name : string|null = null
Return values
int|null

prepareInterval()

protected prepareInterval(ServerRequestInterface|null $request, array<string|int, mixed> &$params, string|null &$interval, array<string|int, mixed>|null $timeOptions) : void
Parameters
$request : ServerRequestInterface|null
$params : array<string|int, mixed>
$interval : string|null
$timeOptions : array<string|int, mixed>|null
Tags
throws
NotFoundException

prepareLang()

protected prepareLang(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : string|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
string|null

prepareLimit()

Prepare and returns the 'limit' value.

protected prepareLimit(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int $defaultValue = 0 ][, string $property = Pagination::LIMIT ]) : int
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
$defaultValue : int = 0
$property : string = Pagination::LIMIT
Return values
int

prepareMargin()

Prepare and returns the 'margin' flag value.

protected prepareMargin(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
bool|null

prepareMock()

Prepare and returns the 'mock' value.

protected prepareMock(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : bool|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
bool|null

prepareOffset()

Prepare and returns the 'offset' value.

protected prepareOffset(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int $defaultValue = 0 ]) : int
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
$defaultValue : int = 0
Return values
int

prepareOrder()

protected prepareOrder(ServerRequestInterface|null $request, array<string|int, mixed>|null &$params, mixed &$order) : void
Parameters
$request : ServerRequestInterface|null
$params : array<string|int, mixed>|null
$order : mixed
Tags
throws
NotFoundException

prepareParamsFacets()

Try to creates the facets definition with the $this->params array definition of the controller.

protected prepareParamsFacets(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed> &$facets = [] ][, array<string|int, mixed>|null &$params = [] ]) : void

Target all 'facets' definitions.

Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$facets : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = []
Tags
example

To list with the controller multiple things by ids, you can invoke the route url : https://myapi/products?id=[12,255,300]

1 - Initialize the facets in the model definition :

FACETS =>
[
    Prop::ID =>
    [
         Facet::TYPE       => Facet::IN ,
         Facet::EXPRESSION => [ SQL::COLUMN => $primaryKey , SQL::TABLE => $tableAlias , SQL::ALTER => StringFunction::RTRIM   ] ,
    ] ,
]

2 - Defines the paramters behavior in the controller definition :

ControllerParam::PARAMS => [ Prop::ID => ControllerParam::FACETS ]

prepareQuantity()

protected prepareQuantity(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, int|null $defaultValue = null ]) : int|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
$defaultValue : int|null = null
Return values
int|null

prepareSearch()

protected prepareSearch(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : string|null
Parameters
$request : ServerRequestInterface|null
$args : array<string|int, mixed> = []
$params : array<string|int, mixed>|null = null
Return values
string|null

prepareSkin()

Prepare and determine the effective skin for a request or method.

protected prepareSkin(ServerRequestInterface|null $request[, array<string, mixed> $init = [] ][, array<string, mixed>|null &$params = null ][, string|null $method = null ]) : string|null

This method considers:

  • Initialization array
  • Method-specific skin overrides
  • Query parameter in the request
  • Default skin fallback
  • Validation against available skins

Example:

$skin = $this->prepareSkin($request, ['skinDefault' => 'main'], $params, 'edit');
Parameters
$request : ServerRequestInterface|null

Optional HTTP request to read query parameters from.

$init : array<string, mixed> = []

Optional initialization array.

$params : array<string, mixed>|null = null

Reference to an array where the chosen skin will be stored.

$method : string|null = null

Optional controller method name to apply method-specific skin.

Return values
string|null

Returns the prepared skin name in lowercase, or null if invalid or "main".

prepareSort()

Prepares the sorting parameter based on the given request and arguments.

protected prepareSort(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, string|null $default = null ][, string $name = ControllerParam::SORT ]) : string|null
Parameters
$request : ServerRequestInterface|null

The request object, which may contain a sorting parameter.

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

An associative array of arguments, which may include a predefined sorting value.

$params : array<string|int, mixed>|null = null

A reference to an array where the resolved sorting parameter will be stored.

$default : string|null = null
$name : string = ControllerParam::SORT
Return values
string|null

The resolved sorting parameter or the default sorting value if none is provided.

prepareTimezone()

Prepare the timezone component.

protected prepareTimezone(ServerRequestInterface|null $request, array<string|int, mixed>|null &$params, string|null &$timezone, array<string|int, mixed>|null $timeOptions[, string $defaultValue = 'Europe/Paris' ]) : void
Parameters
$request : ServerRequestInterface|null
$params : array<string|int, mixed>|null
$timezone : string|null
$timeOptions : array<string|int, mixed>|null
$defaultValue : string = 'Europe/Paris'
Tags
throws
Exception

        
On this page

Search results