Entity
in package
Tags
Table of Contents
Properties
- $id : int
- $_fieldTypes : array<string, Types::*>
- $_updatedFields : array<string|int, mixed>
Methods
- __call() : mixed
- Each time a setter is called, push the part after set into an array: for instance setId will save Id in the updated fields array so it can be easily used to create the getter method
- columnToProperty() : string
- Transform a database columnname to a property
- fromParams() : static
- Simple alternative constructor for building entities from a request
- fromRow() : static
- Maps the keys of the row array to the attributes
- getFieldTypes() : array<string, Types::*>
- getId() : int
- getUpdatedFields() : array<string|int, mixed>
- propertyToColumn() : string
- Transform a property to a database column name
- resetUpdatedFields() : void
- Marks the entity as clean needed for setting the id after the insertion
- setId() : void
- slugify() : string
- Slugify the value of a given attribute Warning: This doesn't result in a unique value
- addType() : void
- Adds type information for a field so that it's automatically cast to that value once its being returned from the database
- getter() : mixed
- Generic getter for properties
- isGetterForBoolProperty() : bool
- markFieldUpdated() : void
- Mark am attribute as updated
- setter() : void
- Generic setter for properties
Properties
$id
public
int
$id
$_fieldTypes
private
array<string, Types::*>
$_fieldTypes
= ['id' => 'integer']
$_updatedFields
private
array<string|int, mixed>
$_updatedFields
= []
Methods
__call()
Each time a setter is called, push the part after set into an array: for instance setId will save Id in the updated fields array so it can be easily used to create the getter method
public
__call(string $methodName, array<string|int, mixed> $args) : mixed
Parameters
- $methodName : string
- $args : array<string|int, mixed>
Tags
columnToProperty()
Transform a database columnname to a property
public
columnToProperty(string $columnName) : string
Parameters
- $columnName : string
-
the name of the column
Tags
Return values
string —the property name
fromParams()
Simple alternative constructor for building entities from a request
public
static fromParams(array<string|int, mixed> $params) : static
Parameters
- $params : array<string|int, mixed>
-
the array which was obtained via $this->params('key') in the controller
Tags
Return values
staticfromRow()
Maps the keys of the row array to the attributes
public
static fromRow(array<string|int, mixed> $row) : static
Parameters
- $row : array<string|int, mixed>
-
the row to map onto the entity
Tags
Return values
staticgetFieldTypes()
public
getFieldTypes() : array<string, Types::*>
Tags
Return values
array<string, Types::*> —with attribute and type
getId()
public
getId() : int
Return values
intgetUpdatedFields()
public
getUpdatedFields() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —array of updated fields for update query
propertyToColumn()
Transform a property to a database column name
public
propertyToColumn(string $property) : string
Parameters
- $property : string
-
the name of the property
Tags
Return values
string —the column name
resetUpdatedFields()
Marks the entity as clean needed for setting the id after the insertion
public
resetUpdatedFields() : void
Tags
setId()
public
setId(int $id) : void
Parameters
- $id : int
slugify()
Slugify the value of a given attribute Warning: This doesn't result in a unique value
public
slugify(string $attributeName) : string
Parameters
- $attributeName : string
-
the name of the attribute, which value should be slugified
Tags
Return values
string —slugified value
addType()
Adds type information for a field so that it's automatically cast to that value once its being returned from the database
protected
addType(string $fieldName, Types::* $type) : void
Parameters
- $fieldName : string
-
the name of the attribute
- $type : Types::*
-
the type which will be used to match a cast
Tags
getter()
Generic getter for properties
protected
getter(string $name) : mixed
Parameters
- $name : string
Tags
isGetterForBoolProperty()
protected
isGetterForBoolProperty(string $methodName) : bool
Parameters
- $methodName : string
Tags
Return values
boolmarkFieldUpdated()
Mark am attribute as updated
protected
markFieldUpdated(string $attribute) : void
Parameters
- $attribute : string
-
the name of the attribute
Tags
setter()
Generic setter for properties
protected
setter(string $name, array<string|int, mixed> $args) : void
Parameters
- $name : string
- $args : array<string|int, mixed>