helpers
Table of Contents
Functions
- getController() : Controller|null
- Retrieves a controller instance from a PSR-11 container if available.
- getModel() : Model|null
- Resolves a model instance from a PSR-11 container or returns a default.
Functions
getController()
Retrieves a controller instance from a PSR-11 container if available.
getController([array<string|int, mixed>|string|null|Controller $definition = null ][, ContainerInterface|null $container = null ][, Controller|null $default = null ]) : Controller|null
This function attempts to fetch a controller by its identifier ($id
)
from the given container. If the container is provided and contains the
specified entry, it is resolved and returned if it is an instance of
Controller. Otherwise, the optional $default
controller is returned.
Parameters
- $definition : array<string|int, mixed>|string|null|Controller = null
-
The controller definition within the container.
- $container : ContainerInterface|null = null
-
The PSR-11 container to fetch the controller from (optional).
- $default : Controller|null = null
-
A fallback controller to return if the container does not provide one (optional).
Tags
Return values
Controller|null —The resolved controller instance or the provided default value, or null
if none found.
getModel()
Resolves a model instance from a PSR-11 container or returns a default.
getModel([array<string|int, mixed>|string|Model|null $definition = null ][, ContainerInterface|null $container = null ][, Model|null $default = null ]) : Model|null
This function attempts to retrieve a Model
instance based on the provided
definition. The definition can be:
- A
Model
instance (returned directly), - An array containing a
ModelParam::MODEL
key, - A string identifier for a model in a PSR-11 container.
Parameters
- $definition : array<string|int, mixed>|string|Model|null = null
-
The model definition, which can be:
- a Model instance,
- an array with key
ModelParam::MODEL
, - a string identifier in the container,
- or null.
- $container : ContainerInterface|null = null
-
Optional PSR-11 container used to resolve a string definition.
- $default : Model|null = null
-
Optional fallback model returned if none could be resolved.
Tags
Return values
Model|null —The resolved Model
instance, the provided default, or null
if none found.