Oihana PHP System

getModel.php

Table of Contents

Functions

getModel()  : Model|null
Resolves a model instance from a PSR-11 container or returns a default.

Functions

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
throws
ContainerExceptionInterface

If an error occurs while retrieving the model from the container.

throws
NotFoundExceptionInterface

If a string definition is provided but not found in the container.

Return values
Model|null

The resolved Model instance, the provided default, or null if none found.


        
On this page

Search results