Model
in package
implements
JsonSerializable
Base class for models.
Table of Contents
Interfaces
- JsonSerializable
Constants
Properties
- $crudAction : int
- $fillable : array<string|int, mixed>
- $guarded : array<string|int, mixed>
- $instantiated : bool
- $onCommit : array<string|int, mixed>
- $primary : string|null
- $properties : array<string|int, mixed>
- $table : string|null
- $where : array<string|int, mixed>
Methods
- __call() : void
- Calls unreachable methods.
- __callStatic() : mixed
- Makes the calls to a private|protected methods with arguments.
- __get() : mixed
- Returns the value of the property.
- __set() : void
- Sets properties dynamically.
- commit() : mixed
- Commits pending Insert-Update-Delete transactions.
- jsonSerialize() : void
- Customizes the output when this object is printed with json_encode function.
- setIntantiation() : void
- Sets the value of the property instantiated to $state.
- static() : void
- create() : Model
- Sets new values as pending on commit event for INSERT action.
- createMany() : Model
- Inserts multiple records at once.
- delete() : mixed
- Deletes current model from table.
- find() : mixed
- Finds only one record from current model.
- getFillableColumns() : array<string|int, mixed>
- Get the final columns to fill up.
- getTableNameFromModel() : string|null
- Returns the DB table linked to current model.
- parseWhere() : void
- Parses the $where clause and sets new values for the placeholders and bound values.
- prepareQueryFromKeys() : string
- Prepares a query string from an array of keys.
- save() : mixed
- Updates the current model.
- setPendingValuesForCommit() : void
- Stores pending values for further commit on CRUD actions.
- setPropertiesFromModel() : void
- Brings all columns from current model/table and set them as properties.
- transformRecordToModel() : Model
- Transforms a record into a new model.
- update() : Model
- Sets new values as pending on commit event for UPDATE action.
Constants
DELETE
public
mixed
DELETE
= 8
INSERT
public
mixed
INSERT
= 2
SELECT
public
mixed
SELECT
= 1
UPDATE
public
mixed
UPDATE
= 4
Properties
$crudAction
protected
int
$crudAction
= \Classes\Model::SELECT
$fillable
protected
array<string|int, mixed>
$fillable
= []
List of specific column names that can be filled on INSERTS and UPDATES.
$guarded
protected
array<string|int, mixed>
$guarded
= []
List of specific column names excluded from INSERTS and UPDATES.
$instantiated
protected
bool
$instantiated
= false
$onCommit
protected
array<string|int, mixed>
$onCommit
= []
Pending values for commit : UPDATE and INSERT.
$primary
protected
string|null
$primary
= 'id'
Primary key to look for as unique value from table.
$properties
protected
array<string|int, mixed>
$properties
= []
List of dynamic properties (columns). This array will be filled up with values from model table.
$table
protected
string|null
$table
= null
Defines the name of the table to be used for this model.
$where
protected
array<string|int, mixed>
$where
= []
Pending WHERE clause for UPDATE and DELETE actions.
Methods
__call()
Calls unreachable methods.
public
__call(string $method, mixed $arguments) : void
Parameters
- $method : string
- $arguments : mixed
__callStatic()
Makes the calls to a private|protected methods with arguments.
public
static __callStatic(string $method, mixed $arguments) : mixed
Parameters
- $method : string
- $arguments : mixed
__get()
Returns the value of the property.
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__set()
Sets properties dynamically.
public
__set(string $property, mixed $value) : void
Parameters
- $property : string
- $value : mixed
Tags
commit()
Commits pending Insert-Update-Delete transactions.
public
commit() : mixed
jsonSerialize()
Customizes the output when this object is printed with json_encode function.
public
jsonSerialize() : void
setIntantiation()
Sets the value of the property instantiated to $state.
public
setIntantiation(bool $state) : void
Parameters
- $state : bool
static()
public
static() : void
?Model find(int|array $filter, ?array $columns = null) Finds only one record from current model.
create()
Sets new values as pending on commit event for INSERT action.
private
create(array<string|int, mixed> $newValues) : Model
Parameters
- $newValues : array<string|int, mixed>
Tags
Return values
ModelcreateMany()
Inserts multiple records at once.
private
createMany(array<string|int, mixed> $records) : Model
Parameters
- $records : array<string|int, mixed>
Tags
Return values
Modeldelete()
Deletes current model from table.
private
delete([array<string|int, mixed> $where = [] ]) : mixed
Parameters
- $where : array<string|int, mixed> = []
find()
Finds only one record from current model.
private
find(int|array<string|int, mixed> $filter[, array<string|int, mixed>|null $columns = null ]) : mixed
Parameters
- $filter : int|array<string|int, mixed>
- $columns : array<string|int, mixed>|null = null
Return values
mixed —Model, null or array
getFillableColumns()
Get the final columns to fill up.
private
getFillableColumns() : array<string|int, mixed>
Return values
array<string|int, mixed>getTableNameFromModel()
Returns the DB table linked to current model.
private
getTableNameFromModel() : string|null
Return values
string|nullparseWhere()
Parses the $where clause and sets new values for the placeholders and bound values.
private
parseWhere(array<string|int, mixed> $where, string &$placeholders, array<string|int, mixed> &$boundValues) : void
Parameters
- $where : array<string|int, mixed>
- $placeholders : string
- $boundValues : array<string|int, mixed>
Tags
prepareQueryFromKeys()
Prepares a query string from an array of keys.
private
prepareQueryFromKeys(array<string|int, mixed> $keys[, string $operator = 'AND' ]) : string
It concatenates a logic operator.
Parameters
- $keys : array<string|int, mixed>
- $operator : string = 'AND'
Return values
stringsave()
Updates the current model.
private
save() : mixed
setPendingValuesForCommit()
Stores pending values for further commit on CRUD actions.
private
setPendingValuesForCommit(array<string|int, mixed> $newValues) : void
Parameters
- $newValues : array<string|int, mixed>
setPropertiesFromModel()
Brings all columns from current model/table and set them as properties.
private
setPropertiesFromModel() : void
transformRecordToModel()
Transforms a record into a new model.
private
transformRecordToModel(array<string|int, mixed> $record, string $class) : Model
Parameters
- $record : array<string|int, mixed>
- $class : string
Return values
Modelupdate()
Sets new values as pending on commit event for UPDATE action.
private
update([array<string|int, mixed> $updatedValues = [] ][, array<string|int, mixed> $where = [] ]) : Model
Parameters
- $updatedValues : array<string|int, mixed> = []
- $where : array<string|int, mixed> = []