Controller uses ApiTrait, AppTrait, BenchTrait, ContainerTrait, ConfigTrait, GetParamTrait, HttpCacheTrait, JsonTrait, LoggerTrait, MockTrait, PaginationTrait, PathTrait, RouterTrait, StatusTrait, ToStringTrait, ValidatorTrait
Base abstract Controller.
Provides the foundational logic for all controllers, including: dependency injection, logging, routing, validation, caching, JSON handling, benchmarking, configuration, and API initialization.
This class is meant to be extended by all application controllers.
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.
- $jsonOptions : int
- The default json options used in the controller.
- $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
- Strategy to fetch parameters: 'both' (default), 'body' only, or 'query' only.
- $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.
- $validator : Factory
- The validator reference.
- $api : array<string|int, mixed>
- The default api settings.
- $app : App
- The Slim App instance.
- $httpCache : CacheProvider|null
- The cache provider reference (optional).
- $router : RouteParserInterface
- The router parser instance.
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() : mixed|null
- Get a single parameter from the request body.
- getBodyParams() : array<string|int, mixed>|null
- Get multiple parameters from the request body.
- getFullOwnerPath() : string
- Returns the full owner path url with a specific owner identifier.
- getLogger() : LoggerInterface|null
- Returns the logger reference.
- 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.
- getRoute() : RouteInterface|null
- Returns the current Request route reference.
- getUrl() : string
- Generates a full URL for the application.
- getValidatorError() : ResponseInterface|null
- Returns an error if the validator fails.
- info() : void
- Interesting events.
- initConfigPath() : static
- Initialize the configuration path from an array or a DI container.
- initCustomValidationRules() : array<string|int, mixed>
- Returns the list of all extra-rules to initialize the validator.
- initializeApi() : static
- Initializes the internal `api` settings.
- initializeApp() : static
- Initializes the internal `app` property.
- initializeBench() : $this
- Initialize the `bench` property.
- initializeConfig() : static
- Initialize the configuration from an array or a DI container.
- 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.
- prepareRules() : array<string|int, mixed>
- Merge the default common and the specific method's rules.
- 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.
- 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
- 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
$jsonOptions
The default json options used in the controller.
public
int
$jsonOptions
= \oihana\enums\JsonParam::JSON_NONE
$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
Strategy to fetch parameters: 'both' (default), 'body' only, or 'query' only.
public
string
$paramsStrategy
= \oihana\enums\http\HttpParamStrategy::BOTH
$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
$validator
The validator reference.
public
Factory
$validator
$api
The default api settings.
protected
array<string|int, mixed>
$api
= []
$app
The Slim App instance.
protected
App
$app
Tags
$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.
$router
The router parser instance.
protected
RouteParserInterface
$router
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
__toString()
Returns a String representation of the object.
public
__toString() : string
Tags
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
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|nullgetBasePath()
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 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|nullgetBodyParams()
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.
getFullOwnerPath()
Returns the full owner path url with a specific owner identifier.
public
getFullOwnerPath(string $id) : string
Parameters
- $id : string
Return values
stringgetLogger()
Returns the logger reference.
public
getLogger() : LoggerInterface|null
Return values
LoggerInterface|nullgetParam()
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
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>|nullgetQueryParam()
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|nullgetRoute()
Returns the current Request route reference.
public
getRoute(ServerRequestInterface|null $request) : RouteInterface|null
Parameters
- $request : ServerRequestInterface|null
Return values
RouteInterface|nullgetUrl()
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.
getValidatorError()
Returns an error if the validator fails.
public
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|nullinfo()
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> = []
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
Return values
static —Returns the current instance for method chaining.
initCustomValidationRules()
Returns the list of all extra-rules to initialize the validator.
public
initCustomValidationRules() : array<string|int, mixed>
Overrides this method to extends the default rules definitions.
Return values
array<string|int, mixed>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
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 with a specific priority:
- From the provided initialization array (e.g., ['app' => App instance]).
- If not in the array, from the DI container (using App::class or a custom key from init).
It throws an exception if no valid App instance can be found. This priority allows for easy overriding/mocking during tests.
Parameters
- $init : array<string|int, mixed> = []
-
Optional initialization array.
- $container : ContainerInterface|null = null
-
Optional DI container.
Tags
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
$thisinitializeConfig()
Initialize the configuration from an array or a DI container.
public
initializeConfig([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Example usage:
$this->initializeConfig( ['config' => ['db_host' => 'localhost']] ) ;
echo $this->config['db_host'] ; // 'localhost'
// Using a DI container
$container->set( 'my_config' , ['db_name' => 'prod'] ) ;
$this->initializeConfig( ['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
Return values
static —Returns the current instance for method chaining.
initializeHttpCache()
Initialize the internal HTTP cache provider.
public
initializeHttpCache([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Priority order:
$init[ControllerParam::HTTP_CACHE]$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
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
Return values
staticinitializeLoggable()
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
Return values
staticinitializeLogger()
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
nullor an empty value, which will default to LoggerInterface::class depending on the$useDefaultparameter.
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
$initdoes not provide a valid logger string. Defaults totrue.
Tags
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
$thisinitializePagination()
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
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
-
$strategy Either a string strategy or an array with key ControllerParam::PARAMS_STRATEGY.
Tags
Return values
staticinitializePath()
Sets the path of the controller.
public
initializePath([array<string|int, mixed> $init = [] ]) : static
Parameters
- $init : array<string|int, mixed> = []
-
return static
Return values
staticinitializeRouterParser()
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
Return values
static —Returns the current instance for method chaining
initializeValidator()
Sets the current internal validator of the controller.
public
initializeValidator([array<string|int, mixed> $init = [] ]) : static
By default, creates a new Validator instance and initialize it.
Parameters
- $init : array<string|int, mixed> = []
Tags
Return values
staticjsonResponse()
Return a JSON response
public
jsonResponse(ResponseInterface $response[, mixed $data = null ][, int $status = HttpStatusCode::OK ]) : ResponseInterface
Parameters
- $response : ResponseInterface
- $data : mixed = null
- $status : int = HttpStatusCode::OK
Return values
ResponseInterfacelog()
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> = []
prepareRules()
Merge the default common and the specific method's rules.
public
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>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 = HttpStatusCode::FOUND ]) : ResponseInterface
Parameters
- $response : ResponseInterface
- $url : string
- $status : int = HttpStatusCode::FOUND
Return values
ResponseInterfacestartBench()
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|nullstatus()
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
Return values
ResponseInterface|nullsuccess()
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
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
Return values
array<string|int, mixed>|nullgetParamBool()
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
Return values
bool|nullgetParamDefaultValueInModel()
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
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
Return values
float|nullgetParamFloatWithRange()
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
Return values
float|nullgetParamInt()
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
Return values
int|nullgetParamIntWithRange()
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
Return values
int|nullgetParamNumberWithRange()
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
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
Return values
string|nullurlFor()
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