Model uses DebugTrait, ToStringTrait
A minimal, container-aware base class for all models of the library.
Model wires three foundational concerns together and leaves the data-access logic to its
subclasses (most notably PDOModel, which mixes in
PDOTrait):
- Dependency injection: the PHP-DI Container passed to the constructor is stored on
$containerand reused by the initializers to resolve services declared by name (logger, PDO, …). - Debug flag: provided by DebugTrait and toggled through the
debuginit key. - Logging: a PSR-3 LoggerInterface resolved either directly or from a container id via
the
loggerinit key.
The constructor follows the library-wide "initialize from an options array" convention: every
behaviour is configured through a single associative $init array whose keys are documented per
initializer. Each initialize*() helper returns $this, allowing the fluent chaining used below.
Tags
Table of Contents
Properties
- $container : Container
- The PHP-DI container reference, used to resolve services by name throughout the model.
Methods
- __construct() : mixed
- Creates a new Model instance and initializes the debug flag, the logger and the mock flag from the given options array.
Properties
$container
The PHP-DI container reference, used to resolve services by name throughout the model.
public
Container
$container
Methods
__construct()
Creates a new Model instance and initializes the debug flag, the logger and the mock flag from the given options array.
public
__construct(Container $container[, LoggerInterface|string|null, mock?: bool|null} $init = [] ]) : mixed
Parameters
- $container : Container
-
The DI container used to resolve services referenced by name (e.g. the logger), and stored on
$containerfor later use. - $init : LoggerInterface|string|null, mock?: bool|null} = []
-
Optional initialization array with keys:
- debug : Whether the debug mode is active (default
false). - logger : A PSR-3 LoggerInterface instance, or the container service id of one to resolve.
- mock : Whether the model runs in mock mode, e.g. to bypass real I/O in tests (default
false).
- debug : Whether the debug mode is active (default