Model uses DebugTrait, ToStringTrait
A base model class that integrates a PDO instance with dependency injection container support.
This class uses the PDOTrait to provide PDO-related database operations, binding, and fetching.
The model can be initialized with configuration options such as alters, binds, schema, defer assignment, logger, mock objects, and the PDO instance itself.
Tags
Table of Contents
Constants
Properties
- $container : Container
- The DI container reference.
- $debug : bool
- Indicates if use the debug mode.
- $mock : bool
- The mock flag to test the model.
Methods
- __construct() : mixed
- Creates a new Model instance.
- __toString() : string
- Returns a String representation of the object.
- fetch() : mixed
- fetchAll() : array<string|int, mixed>
- fetchColumn() : mixed
- initializeMock() : bool
- Initialize the mock flag.
- isMock() : bool
- Indicates if the document use the mock mode.
Constants
DEBUG
The 'debug' parameter constant.
public
mixed
DEBUG
= 'debug'
MOCK
The 'mock' parameter constant.
public
mixed
MOCK
= 'mock'
Properties
$container
The DI container reference.
public
Container
$container
$debug
Indicates if use the debug mode.
public
bool
$debug
= false
$mock
The mock flag to test the model.
public
bool
$mock
= false
Methods
__construct()
Creates a new Model instance.
public
__construct(Container $container[, LoggerInterface|string|null, mock: bool|null} $init = [] ]) : mixed
Parameters
- $container : Container
-
The DI container to retrieve services like PDO and logger.
- $init : LoggerInterface|string|null, mock: bool|null} = []
-
Optional initialization array with keys:
- debug : Indicates if the debug mode is active (Default false).
- logger : The optional PSR3 LoggerInterface reference or the name of the reference in the DI Container.
- mock : Indicates if the model use a mock process (Default false).
Tags
__toString()
Returns a String representation of the object.
public
__toString() : string
Tags
Return values
string —A string representation of the object.
fetch()
public
fetch(string $query[, array<string|int, mixed> $bindVars = = '[]' ]) : mixed
Fetch a single record from the database.
Parameters
- $query : string
- $bindVars : array<string|int, mixed> = = '[]'
fetchAll()
public
fetchAll(string $query[, array<string|int, mixed> $bindVars = = '[]' ]) : array<string|int, mixed>
Fetch all matching records from the database.
Parameters
- $query : string
- $bindVars : array<string|int, mixed> = = '[]'
Return values
array<string|int, mixed>fetchColumn()
public
fetchColumn(string $query[, array<string|int, mixed> $bindVars = = '[]' ][, int $column = = '0' ]) : mixed
Fetch a single column from the first row.
Parameters
- $query : string
- $bindVars : array<string|int, mixed> = = '[]'
- $column : int = = '0'
initializeMock()
Initialize the mock flag.
public
initializeMock([array<string|int, mixed> $init = [] ]) : bool
Parameters
- $init : array<string|int, mixed> = []
Return values
boolisMock()
Indicates if the document use the mock mode.
public
isMock([array<string|int, mixed> $init = [] ]) : bool
Parameters
- $init : array<string|int, mixed> = []