getDocumentsModel.php
Table of Contents
Functions
- getDocumentsModel() : DocumentsModel|null
- Resolves a {@see DocumentsModel} instance from a PSR-11 container or returns a default.
Functions
getDocumentsModel()
Resolves a {@see DocumentsModel} instance from a PSR-11 container or returns a default.
getDocumentsModel([string|DocumentsModel|null $definition = null ][, ContainerInterface|null $container = null ][, DocumentsModel|null $default = null ]) : DocumentsModel|null
This helper function provides a flexible way to obtain a DocumentsModel instance:
- If
$definitionis already aDocumentsModel, it is returned as-is. - If
$definitionis a string and$containerimplements ContainerInterface, the function attempts to resolve the corresponding service from the container. - If resolution fails, the provided
$default(if any) is returned instead.
This pattern allows for safe dependency resolution in controllers or services, without requiring explicit type-checking or container awareness in user code.
Parameters
- $definition : string|DocumentsModel|null = null
-
The model definition — either:
- a
DocumentsModelinstance (returned directly), - a string service identifier (resolved from
$container), - or
null(uses$default).
- a
- $container : ContainerInterface|null = null
-
Optional PSR-11 container to resolve string identifiers.
- $default : DocumentsModel|null = null
-
Optional fallback model if no valid instance is found.
Tags
Return values
DocumentsModel|null —The resolved model, the provided default, or null if none.