Oihana PHP System

Controller uses ApiTrait, AppTrait, BenchTrait, ContainerTrait, ConfigTrait, GetParamTrait, HttpCacheTrait, JsonTrait, LoggerTrait, MockTrait, PaginationTrait, PathTrait, RouterTrait, StatusTrait, ToStringTrait, ValidatorTrait

AbstractYes

Table of Contents

Constants

CONFIG  = 'config'
The 'config' key for initialization arrays.
CONFIG_PATH  = 'configPath'
The 'configPath' key for initialization arrays.
LOGGABLE  = 'loggable'
The 'loggable' parameter constant.
LOGGER  = 'logger'
The 'logger' parameter constant.

Properties

$bench  : bool
The bench flag to test the script execution time of a function.
$conditions  : array<string|int, mixed>|null
The optional conditions settings to validate things.
$config  : array<string|int, mixed>
$configPath  : string
$container  : Container
The DI container reference.
$customRules  : array<string|int, mixed>
The custom validation rules definitions.
$fullPath  : string
The full path reference.
$loggable  : bool
The loggable flag.
$mock  : bool
The mock flag to test the model.
$ownerPath  : string|null
The path of an owner reference.
$pagination  : Pagination|null
The pagination definition.
$paramsStrategy  : string
The internal strategy to get body or query parameters.
$path  : string
The path reference.
$rules  : array<string|int, mixed>
The rules definitions used in the prepareRules method to initialize a validation process in the POST/PATCH/PUT and custom methods.
$api  : array<string|int, mixed>
The default api settings.
$app  : App
The Slim App instance.
$httpCache  : CacheProvider|null
The cache provider reference (optional).
$jsonOptions  : int
The default json options used in the controller.
$router  : RouteParserInterface
The router parser instance.
$validator  : Factory
The validator reference.

Methods

__construct()  : mixed
Creates a new Controller instance.
__toString()  : string
Returns a String representation of the object.
addRules()  : void
Register the extra validator's rules.
alert()  : void
Action must be taken immediately.
allowCache()  : ResponseInterface
Enable HTTP caching for the given response.
alter()  : mixed
Alter the specific thing.
critical()  : void
Critical conditions.
debug()  : void
Detailed debug information.
denyCache()  : ResponseInterface
Enforce the removal of browser cache for a response.
emergency()  : void
System is unusable.
endBench()  : string|null
Stop the bench.
error()  : void
Runtime errors that do not require immediate action but should typically be logged and monitored.
fail()  : ResponseInterface|null
Formats a specific error status message with a code and an errors array representation of all errors.
getBasePath()  : string
Returns the base path of the application.
getBodyParam()  : object|null
Get a parameter in the body of the current request.
getBodyParams()  : array<string|int, mixed>|null
Get the parameters in the body of the current request.
getFullOwnerPath()  : string
Returns the full owner path url with a specific owner identifier.
getLogger()  : LoggerInterface|null
Returns the logger reference.
getParam()  : mixed
Get the parameters in the query or body of the current request.
getParams()  : array<string|int, mixed>|null
Get the parameters in the query or body of the current request.
getQueryParam()  : string|null
Get the parameter value in the body of the current request.
getRoute()  : RouteInterface|null
Returns the current Request route reference.
getUrl()  : string
Generates a full URL for the application.
info()  : void
Interesting events.
initConfig()  : static
Initialize the configuration from an array or a DI container.
initConfigPath()  : static
Initialize the configuration path from an array or a DI container.
initializeApi()  : static
Initializes the internal `api` settings.
initializeApp()  : static
Initializes the internal `app` property.
initializeBench()  : $this
Initialize the `bench` property.
initializeHttpCache()  : static
Initialize the internal HTTP cache provider.
initializeJsonOptions()  : static
Initialize the internal $jsonOptions property.
initializeLoggable()  : static
Initialize the loggable flag.
initializeLogger()  : static
Initializes the logger reference for the current instance.
initializeMock()  : $this
Initialize the `mock` property.
initializePagination()  : static
Initializes the `pagination` property.
initializeParamsStrategy()  : static
Initialize the params strategy : 'both' (default), 'body' (only), 'query' (only).
initializePath()  : static
Sets the path of the controller.
initializeRouterParser()  : static
Initializes the internal `router` property.
initializeValidator()  : static
Sets the current internal validator of the controller.
jsonResponse()  : ResponseInterface
Return a JSON response
log()  : void
Logs with an arbitrary level.
notice()  : void
Normal but significant events.
redirectFor()  : ResponseInterface
Redirects the response to a named route.
redirectResponse()  : ResponseInterface
Redirect to a specific URL target.
startBench()  : int|float|null
Start the bench process.
status()  : ResponseInterface|null
Outputs a response status message.
success()  : mixed
Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.
warning()  : void
Exceptional occurrences that are not errors.
withEtag()  : ResponseInterface
Add an `ETag` header to a PSR-7 response object.
withExpires()  : ResponseInterface
Add an `Expires` header to a PSR-7 response object.
withLastModified()  : ResponseInterface
Add a `Last-Modified` header to a PSR-7 response object.
getParamBool()  : int|null
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
getParamFloatWithRange()  : float|null
getParamInt()  : int|null
getParamIntWithRange()  : int|null
getParamNumberWithRange()  : int|null
getParamString()  : string|null
getValidatorError()  : ResponseInterface|null
Returns an error if the validator fails.
initCustomValidationRules()  : array<string|int, mixed>
Returns the list of all extra-rules to initialize the validator.
prepareRules()  : array<string|int, mixed>
Merge the default common and the specific method's rules.
urlFor()  : string
Builds the full URL for a named route including the base URL.

Constants

CONFIG

The 'config' key for initialization arrays.

public mixed CONFIG = 'config'

CONFIG_PATH

The 'configPath' key for initialization arrays.

public mixed CONFIG_PATH = 'configPath'

LOGGABLE

The 'loggable' parameter constant.

public mixed LOGGABLE = 'loggable'

LOGGER

The 'logger' parameter constant.

public mixed LOGGER = 'logger'

Properties

$bench

The bench flag to test the script execution time of a function.

public bool $bench = false

$conditions

The optional conditions settings to validate things.

public array<string|int, mixed>|null $conditions

$config

public array<string|int, mixed> $config = []

The config reference.

$configPath

public string $configPath = \oihana\enums\Char::EMPTY

The base path of the file to load an external config.

$container

The DI container reference.

public Container $container

$customRules

The custom validation rules definitions.

public array<string|int, mixed> $customRules = []

$fullPath

The full path reference.

public string $fullPath

$loggable

The loggable flag.

public bool $loggable = false

$mock

The mock flag to test the model.

public bool $mock = null

$ownerPath

The path of an owner reference.

public string|null $ownerPath = \oihana\enums\Char::EMPTY

$pagination

The pagination definition.

public Pagination|null $pagination = null

$paramsStrategy

The internal strategy to get body or query parameters.

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

$path

The path reference.

public string $path = \oihana\enums\Char::EMPTY

$rules

The rules definitions used in the prepareRules method to initialize a validation process in the POST/PATCH/PUT and custom methods.

public array<string|int, mixed> $rules = []
Tags
see
More

informations in the the prepareRules method definition.

$api

The default api settings.

protected array<string|int, mixed> $api = []

$app

The Slim App instance.

protected App $app
Tags
access

protected

$httpCache

The cache provider reference (optional).

protected CacheProvider|null $httpCache = null

When set, this property holds a Slim\HttpCache\CacheProvider instance used to modify HTTP response headers for caching.

$jsonOptions

The default json options used in the controller.

protected int $jsonOptions = \oihana\enums\JsonParam::JSON_NONE

$router

The router parser instance.

protected RouteParserInterface $router

$validator

The validator reference.

protected Factory $validator

Methods

__construct()

Creates a new Controller instance.

public __construct(Container $container[, array<string|int, mixed> $init = [] ]) : mixed
Parameters
$container : Container

The DI container reference to initialize the controller.

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

The optional properties to passed-in to initialize the object.

  • string $path : The path expression of the component.
  • Validator $validator : The optional validator of the controller (by default use a basic Validator instance).
Tags
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface

__toString()

Returns a String representation of the object.

public __toString() : string
Tags
throws
ReflectionException
Return values
string

A string representation of the object.

addRules()

Register the extra validator's rules.

public addRules([array<string|int, mixed> $rules = [] ]) : void
Parameters
$rules : array<string|int, mixed> = []
Tags
throws
DependencyException
throws
NotFoundException

alert()

Action must be taken immediately.

public alert(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

allowCache()

Enable HTTP caching for the given response.

public allowCache(ResponseInterface $response[, string $type = 'private' ][, int|string|null $maxAge = null ][, bool $mustRevalidate = false ]) : ResponseInterface

This method sets a Cache-Control header using the underlying CacheProvider. If the HTTP cache provider is not initialized, the response is returned unchanged.

Parameters
$response : ResponseInterface

A PSR-7 response object

$type : string = 'private'

Cache-Control type: "private" or "public"

$maxAge : int|string|null = null

Maximum cache age in seconds or a datetime string parsable by strtotime()

$mustRevalidate : bool = false

Whether to add the "must-revalidate" directive

Return values
ResponseInterface

A new response object with cache headers if the cache provider is available.

alter()

Alter the specific thing.

public alter([mixed $thing = null ][, string|null $lang = null ][, string|null $skin = null ][, array<string|int, mixed>|null $params = null ]) : mixed

Overrides this method to customize the alter strategy.

Parameters
$thing : mixed = null

A generic object to alter.

$lang : string|null = null

The lang optional lang iso code.

$skin : string|null = null

The optional skin mode.

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

The optional params object.

Return values
mixed

The altered thing reference.

critical()

Critical conditions.

public critical(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Application component unavailable, unexpected exception.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

debug()

Detailed debug information.

public debug(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

denyCache()

Enforce the removal of browser cache for a response.

public denyCache(ResponseInterface $response) : ResponseInterface

Equivalent to setting headers like Cache-Control: no-store, no-cache, must-revalidate. If the HTTP cache provider is not initialized, the response is returned unchanged.

Parameters
$response : ResponseInterface

A PSR-7 response object

Return values
ResponseInterface

A new response object with cache denial headers if available.

emergency()

System is unusable.

public emergency(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

endBench()

Stop the bench.

public endBench(int|float|null $timestamp[, array<string|int, mixed> &$options = [] ]) : string|null
Parameters
$timestamp : int|float|null
$options : array<string|int, mixed> = []
Return values
string|null

The time interval of the bench.

error()

Runtime errors that do not require immediate action but should typically be logged and monitored.

public error(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

fail()

Formats a specific error status message with a code and an errors array representation of all errors.

public fail(ResponseInterface|null $response[, int|string|null $code = 400 ][, string|null $details = null ][, array<string|int, mixed> $options = [] ]) : ResponseInterface|null

Ex: A 'not acceptable' http request with a failed validation process

return $this->getError( $response , 406 , 'fields validation failed' , [ 'firstName' => 'firstName is required'  , 'lastName' => 'lastName must be a string' ] ] ) ;
``
Parameters
$response : ResponseInterface|null

The Response reference.

$code : int|string|null = 400

The status code of the response.

$details : string|null = null

The optional error message to overrides the default status message.

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

The optional array to inject in the json object (with an errors)

Return values
ResponseInterface|null

getBasePath()

Returns the base path of the application.

public getBasePath() : string

This corresponds to the path configured in Slim and can be used to generate URLs relative to the application root.

Return values
string

The application's base path (e.g., "/myapp")

getBodyParam()

Get a parameter in the body of the current request.

public getBodyParam(ServerRequestInterface|null $request, string $name) : object|null
Parameters
$request : ServerRequestInterface|null
$name : string
Return values
object|null

getBodyParams()

Get the parameters in the body of the current request.

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

getFullOwnerPath()

Returns the full owner path url with a specific owner identifier.

public getFullOwnerPath(string $id) : string
Parameters
$id : string
Return values
string

getLogger()

Returns the logger reference.

public getLogger() : LoggerInterface|null
Return values
LoggerInterface|null

getParam()

Get the parameters in the query or body of the current request.

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

The name of the parameter to search in the current request

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

The default array reference to fill the value if the parameter is not find.

$throwable : bool = false

Indicates if the method thrown an exception if the parameter not exist in the query or body of the request (default false).

Tags
throws
NotFoundException
Return values
mixed

The parameter value of a default value or null.

getParams()

Get the parameters in the query or body of the current request.

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

getQueryParam()

Get the parameter value in the body of the current request.

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

getRoute()

Returns the current Request route reference.

public getRoute(ServerRequestInterface|null $request) : RouteInterface|null
Parameters
$request : ServerRequestInterface|null
Return values
RouteInterface|null

getUrl()

Generates a full URL for the application.

public getUrl([string $path = '' ][, array<string|int, mixed> $params = [] ][, bool $useNow = false ]) : string

The URL is constructed using the application's base URL, the base path, the optional path, and query parameters.

Parameters
$path : string = ''

Optional relative path to append to the base URL.

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

Optional query parameters as key-value pairs.

$useNow : bool = false

If true, timestamp-like parameters will be processed immediately.

Return values
string

The full URL including base URL, path, and query parameters.

info()

Interesting events.

public info(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: User logs in, SQL logs.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

initConfig()

Initialize the configuration from an array or a DI container.

public initConfig([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

Example usage:

$this->initConfig( ['config' => ['db_host' => 'localhost']] ) ;
echo $this->config['db_host'] ; // 'localhost'

// Using a DI container
$container->set( 'my_config' , ['db_name' => 'prod'] ) ;
$this->initConfig( ['config' => 'my_config' ] , $container ) ;
echo $this->config[ 'db_name' ] ; // 'prod'
Parameters
$init : array<string|int, mixed> = []

Initialization array that may contain 'config' key.

$container : ContainerInterface|null = null

Optional DI container to resolve config entries.

Tags
throws
DependencyException
throws
NotFoundException
throws
NotFoundExceptionInterface
throws
ContainerExceptionInterface
Return values
static

Returns the current instance for method chaining.

initConfigPath()

Initialize the configuration path from an array or a DI container.

public initConfigPath([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

Example usage:

$this->initConfigPath(['configPath' => '/etc/myservice/config']);
echo $this->configPath; // '/etc/myservice/config'

// Using a DI container
$container->set('configPath', '/etc/prod/config');
$this->initConfigPath([], $container);
echo $this->configPath; // '/etc/prod/config'
Parameters
$init : array<string|int, mixed> = []

Initialization array that may contain 'configPath' key.

$container : ContainerInterface|null = null

Optional DI container to resolve path entries.

Tags
throws
DependencyException
throws
NotFoundException
throws
NotFoundExceptionInterface
throws
ContainerExceptionInterface
Return values
static

Returns the current instance for method chaining.

initializeApi()

Initializes the internal `api` settings.

public initializeApi([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

By default, this method search in the DI container a ControllerParam::API definition to initialize the "api" property.

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

Optional initialization array (e.g., ['api' => [ ... ] ] ).

$container : ContainerInterface|null = null

Optional DI container for retrieving the 'api' array representation.

Tags
throws
NotFoundExceptionInterface

If the container is used and the 'api' definition is not found in the DI container.

throws
ContainerExceptionInterface

If the container throws an internal error.

throws
RuntimeException

If no valid App instance is provided or found.

Return values
static

Returns the current controller instance for method chaining.

initializeApp()

Initializes the internal `app` property.

public initializeApp([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

This method retrieves the Slim App instance from either the provided initialization array or the DI container. It throws an exception if no valid App instance can be found.

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

Optional initialization array (e.g., ['app' => App instance]).

$container : ContainerInterface|null = null

Optional DI container for retrieving the App instance.

Tags
throws
NotFoundExceptionInterface

If the container is used and the App class is not found.

throws
ContainerExceptionInterface

If the container throws an internal error.

throws
RuntimeException

If no valid App instance is provided or found.

Return values
static

Returns the current controller instance for method chaining.

initializeBench()

Initialize the `bench` property.

public initializeBench([bool|array<string|int, mixed> $init = [] ]) : $this
Parameters
$init : bool|array<string|int, mixed> = []

Optional initialization array or the bench boolean value.

Return values
$this

initializeHttpCache()

Initialize the internal HTTP cache provider.

public initializeHttpCache([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

Priority order:

  1. $init[ControllerParam::HTTP_CACHE]
  2. $container->get(CacheProvider::class) if available in DI
Parameters
$init : array<string|int, mixed> = []

Optional initialization array

$container : ContainerInterface|null = null

Optional DI container to retrieve the cache provider

Tags
throws
DependencyException

If container dependency cannot be resolved

throws
NotFoundException

If container entry is not found

throws
RuntimeException

If no valid CacheProvider could be assigned.

Return values
static

Returns the current instance for method chaining

initializeJsonOptions()

Initialize the internal $jsonOptions property.

public initializeJsonOptions([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Parameters
$init : array<string|int, mixed> = []
$container : ContainerInterface|null = null
Tags
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface
Return values
static

initializeLoggable()

Initialize the loggable flag.

public initializeLoggable([bool|array<string|int, mixed>|null $init = null ][, ContainerInterface|null $container = null ][, bool|array<string|int, mixed>|null $defaultValue = false ]) : static
Parameters
$init : bool|array<string|int, mixed>|null = null

The definition to initialize the loggable property.

$container : ContainerInterface|null = null
$defaultValue : bool|array<string|int, mixed>|null = false

The default value if the $init argument is not defined.

Tags
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface
Return values
static

initializeLogger()

Initializes the logger reference for the current instance.

public initializeLogger([array<string|int, mixed>|LoggerInterface|string|null $init = null ][, ContainerInterface|null $container = null ][, bool $useDefault = true ]) : static

This method accepts either:

  • A LoggerInterface instance
  • An associative array containing a logger reference under the static::LOGGER key
  • A string representing a service ID or class name resolvable by the container
  • null or an empty value, which will default to LoggerInterface::class depending on the $useDefault parameter.

If a dependency injection container is provided, the method will attempt to resolve the logger service from it. If no valid logger can be resolved, the $this->logger property will be set to null.

Parameters
$init : array<string|int, mixed>|LoggerInterface|string|null = null

Logger initialization data. May be an instance, an array with a logger entry, a string service ID/class name, or null.

$container : ContainerInterface|null = null

Optional dependency injection container used to resolve the logger service.

$useDefault : bool = true

Whether to use LoggerInterface::class as a fallback if $init does not provide a valid logger string. Defaults to true.

Tags
throws
DependencyException

If there is a dependency resolution error.

throws
NotFoundException

If the specified service is not found in the container.

throws
NotFoundExceptionInterface

If the specified service is not found in the container.

throws
ContainerExceptionInterface

If the container encounters a general error.

Return values
static

Returns the current instance for method chaining.

initializeMock()

Initialize the `mock` property.

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

initializePagination()

Initializes the `pagination` property.

public initializePagination([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

This method retrieves the default pagination settings for the application, either from the provided initialization array or from the dependency injection container.

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

Optional initialization array (e.g., ['pagination' => Pagination instance]).

$container : ContainerInterface|null = null

Optional DI container for retrieving the App instance.

Tags
throws
NotFoundExceptionInterface

If the container is used and the App class is not found.

throws
ContainerExceptionInterface

If the container throws an internal error.

Return values
static

Returns the current controller instance for method chaining.

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
Tags
see
getParam

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

Return values
static

initializePath()

Sets the path of the controller.

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

return static

Return values
static

initializeRouterParser()

Initializes the internal `router` property.

public initializeRouterParser([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

The router instance can be provided in the $init array or fetched from the DI container if available.

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

Optional initialization array

$container : ContainerInterface|null = null

Optional DI container

Tags
throws
NotFoundExceptionInterface

If the requested container entry is not found

throws
ContainerExceptionInterface

If the container throws an error during access

throws
RuntimeException

If no router instance can be resolved

Return values
static

Returns the current instance for method chaining

initializeValidator()

Sets the current internal validator of the controller.

public initializeValidator([null|array<string|int, mixed>|Factory $init = null ]) : static

By default, creates a new Validator instance and initialize it.

Parameters
$init : null|array<string|int, mixed>|Factory = null
Tags
throws
DependencyException
throws
NotFoundException
Return values
static

jsonResponse()

Return a JSON response

public jsonResponse(ResponseInterface $response[, mixed $data = null ][, int $status = 200 ]) : ResponseInterface
Parameters
$response : ResponseInterface
$data : mixed = null
$status : int = 200
Return values
ResponseInterface

log()

Logs with an arbitrary level.

public log(mixed $level, string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$level : mixed
$message : string|Stringable
$context : array<string|int, mixed> = []

notice()

Normal but significant events.

public notice(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

redirectFor()

Redirects the response to a named route.

public redirectFor(ResponseInterface $response, string $name[, array<string|int, mixed> $params = [] ][, int $status = 302 ]) : ResponseInterface

The route URL is generated using $this->router->urlFor().

Parameters
$response : ResponseInterface

PSR-7 response instance

$name : string

Name of the route

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

Optional associative array of route parameters

$status : int = 302

HTTP redirect status code (default 302)

Return values
ResponseInterface

PSR-7 response with redirect headers

redirectResponse()

Redirect to a specific URL target.

public redirectResponse(ResponseInterface $response, string $url[, int $status = 302 ]) : ResponseInterface
Parameters
$response : ResponseInterface
$url : string
$status : int = 302
Return values
ResponseInterface

startBench()

Start the bench process.

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

status()

Outputs a response status message.

public status(ResponseInterface|null $response[, mixed $message = Char::EMPTY ][, int|string|null $code = 200 ][, array<string|int, mixed>|null $options = null ]) : ResponseInterface|null
Parameters
$response : ResponseInterface|null
$message : mixed = Char::EMPTY

The message to send.

$code : int|string|null = 200

The status code.

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

The options to passed-in in the status definition.

Tags
example
return $this->getStatus( $response , 'bad request' , '405' );
Return values
ResponseInterface|null

success()

Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.

public success(ServerRequestInterface|null $request, ResponseInterface|null $response[, mixed $data = null ][, array<string|int, mixed>|null $init = null ]) : mixed

Ex: return $this->success( $request , $response , $data , [ Output::PARAMS => $request->getParams() ] ) ;

Parameters
$request : ServerRequestInterface|null

The HTTP request reference.

$response : ResponseInterface|null

The HTTP Response reference.

$data : mixed = null

The data object to returns (output a JSON object).

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

An associative definition to initialize the output object with the optional properties :

    count (int) - The optional number of elements. owner (object|array) - The optional owner reference. options (array) - An associative array of optional properties to add in the output object. params (array) - The optional params to passed-in the getCurrentPath() method when the url option is null. status (int) - The optional status of the response. total (int) - The optional total number of elements. url (string) - The optional url to display.

warning()

Exceptional occurrences that are not errors.

public warning(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

withEtag()

Add an `ETag` header to a PSR-7 response object.

public withEtag(ResponseInterface $response, string $value[, string $type = 'strong' ]) : ResponseInterface

The ETag is used by browsers and proxies for cache validation. If the HTTP cache provider is not initialized, the response is returned unchanged.

Parameters
$response : ResponseInterface

A PSR-7 response object

$value : string

The ETag value

$type : string = 'strong'

The ETag type: either "strong" or "weak"

Return values
ResponseInterface

A new response object with the ETag header set if available

withExpires()

Add an `Expires` header to a PSR-7 response object.

public withExpires(ResponseInterface $response, string|int $time) : ResponseInterface

This header specifies the date and time after which the response is considered stale. If the HTTP cache provider is not initialized, the response is returned unchanged.

Parameters
$response : ResponseInterface

A PSR-7 response object

$time : string|int

A UNIX timestamp or a string compatible with strtotime().

Return values
ResponseInterface

A new response object with the Expires header set if available

withLastModified()

Add a `Last-Modified` header to a PSR-7 response object.

public withLastModified(ResponseInterface $response, int|string $time) : ResponseInterface

This header informs caches of the last modification date of the resource. If the HTTP cache provider is not initialized, the response is returned unchanged.

Parameters
$response : ResponseInterface

A PSR-7 response object

$time : int|string

A UNIX timestamp or a string compatible with strtotime()

Return values
ResponseInterface

A new response object with the Last-Modified header set if available

getParamBool()

protected getParamBool(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $args = [] ][, bool|null $defaultValue = null ][, bool $throwable = false ]) : int|null
Parameters
$request : ServerRequestInterface|null
$name : string
$args : array<string|int, mixed> = []
$defaultValue : bool|null = null
$throwable : bool = false
Tags
throws
NotFoundException
Return values
int|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 $key[, 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

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()

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()

protected getParamInt(ServerRequestInterface|null $request, mixed $name[, array<string|int, mixed> $args = [] ][, int|null $defaultValue = null ][, bool $throwable = false ]) : int|null
Parameters
$request : ServerRequestInterface|null
$name : mixed
$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()

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

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

getValidatorError()

Returns an error if the validator fails.

protected getValidatorError(ResponseInterface|null $response, Validation $validation[, array<string|int, mixed> $errors = [] ][, int|string $code = 400 ]) : ResponseInterface|null
Parameters
$response : ResponseInterface|null
$validation : Validation
$errors : array<string|int, mixed> = []
$code : int|string = 400
Return values
ResponseInterface|null

initCustomValidationRules()

Returns the list of all extra-rules to initialize the validator.

protected initCustomValidationRules() : array<string|int, mixed>

Overrides this method to extends the default rules definitions.

Return values
array<string|int, mixed>

prepareRules()

Merge the default common and the specific method's rules.

protected prepareRules([string|null $method = null ]) : array<string|int, mixed>

You can overrides this method to prepare the validator rules with a specific router method and strategy.

Parameters
$method : string|null = null

The specific rule type to override the default rules definitions.

Return values
array<string|int, mixed>

urlFor()

Builds the full URL for a named route including the base URL.

protected urlFor(string $routeName) : string

Note: Assumes the $router property is initialized and provides a urlFor() method.

Parameters
$routeName : string

Name of the route

Return values
string

Full URL including base URL and route path


        
On this page

Search results