Flex
in package
Flexible models
Tags
Table of Contents
- $_chainer : Chainer
- $_meta : Meta
- Internal variable for meta data like table name
- $_relations : array<string|int, Relation>
- Model relations are stored here
- __call() : mixed
- Magic method to handle getters and setters
- __construct() : mixed
- __toString() : string
- Convert to json by default
- _getPropertyNames() : array<string|int, mixed>
- Internal method to get attribute and relation names based on the original method call.
- _propertyGetterSetter() : mixed
- Internal method to set or set a property
- build() : mixed
- Convert an array/object result to this class this class can be Flex or any class that extended it
- fieldData() : array<string|int, mixed>
- Helper method to extract information about a database field DB should return the following format: {table_name_or_alias}.{field_name}
- getAttributes() : array<string|int, mixed>
- Get all the non-internal attributes of the instance.
- hydrate() : Flex
- Populate the instance with the given data.
- hydrateBelongs() : void
- Hydrate a relationship of the type 'Belong' This method triggers hydration of child objects.
- hydrateCustomClass() : void
- Hydrates this instance with the data from the $data collection.
- hydrateFlex() : void
- Hydrate a Flex object.
- hydrateHas() : void
- Hydrate a relationship of the type 'Has' This method triggers hydration of child objects.
- hydrateHasAndBelongs() : mixed
- hydrateRelations() : void
- Hydrate all the relations found in the instance.
- isEmpty() : bool
- Determine if an object is empty
- isInternal() : bool
- Determine if it's an internal attribute
- isNew() : bool
- Check if it's a new instance or a loaded one
- meta() : Meta
- Get the metadata of the object.
- postDelete() : bool
- Method to be executed after deleting an object.
- postSave() : bool
- Method to be executed after saving an object.
- preDelete() : bool
- Method to be executed before deleting an object.
- preSave() : bool
- Method to be executed before saving an object.
- relations() : RelationsManager
- Get the relations manager object.
- removeTableFields() : array<string|int, mixed>
- Remove all the fields related to an alias or table form the $data collection.
- toArray() : array<string|int, mixed>
- Helper method, turn input data to array
- valid() : bool
- This method should be overriden for object validation.
Properties
$_chainer
public
Chainer
$_chainer
$_meta
Internal variable for meta data like table name
public
Meta
$_meta
$_relations
Model relations are stored here
public
array<string|int, Relation>
$_relations
Methods
__call()
Magic method to handle getters and setters
public
__call(mixed $name, mixed $arguments) : mixed
this method will first try to find an attribute from a getter or setter for an attribute: Example: get{CamelCaseAttr}() set{CamelCaseAttr}()
After that it will look into relationships Example: get{RelationshipName}() set{RelationshipName}()
In the case of getters, if no instance is defined, it will try to create one from the database.
After that it will look for relation names called as a function to enable collection magic methods. This works for 'Has' and 'HasAndBelongs' relations. Format: {camelCaseRelationName}() Examples: users() ownedCars()
All the relationships information is taken from $this->_meta['relations']
Parameters
- $name : mixed
- $arguments : mixed
Return values
mixed —__construct()
public
__construct() : mixed
Return values
mixed —__toString()
Convert to json by default
public
__toString() : string
Return values
string —_getPropertyNames()
Internal method to get attribute and relation names based on the original method call.
public
_getPropertyNames(mixed $name) : array<string|int, mixed>
Parameters
- $name : mixed
Return values
array<string|int, mixed> —_propertyGetterSetter()
Internal method to set or set a property
public
_propertyGetterSetter(mixed $getSetPreffix, mixed $name[, array<string|int, mixed> $arguments = [] ]) : mixed
Parameters
- $getSetPreffix : mixed
- $name : mixed
- $arguments : array<string|int, mixed> = []
Return values
mixed —build()
Convert an array/object result to this class this class can be Flex or any class that extended it
public
static build(mixed $data[, mixed $table = '' ]) : mixed
Parameters
- $data : mixed
- $table : mixed = ''
Return values
mixed —fieldData()
Helper method to extract information about a database field DB should return the following format: {table_name_or_alias}.{field_name}
public
fieldData(string $field) : array<string|int, mixed>
Here we extract the table/alias name, and the field name
Parameters
- $field : string
Return values
array<string|int, mixed> —getAttributes()
Get all the non-internal attributes of the instance.
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —hydrate()
Populate the instance with the given data.
public
hydrate(mixed $data[, string $alias = '' ]) : Flex
If an alias is provided, then it will try to hydrate using that table alias instead.
Internally we are using the 'hydrateRelations' method which starts the recursion loop to hydrate everything available, including child objects.
Internally, $data can be a collection, this happens when querying a 'Has' or 'HasAndBelongs' relation, which returns a row for each relation match.
Parameters
- $data : mixed
-
The array/object to hydrate
- $alias : string = ''
-
Alias used
Return values
Flex —hydrateBelongs()
Hydrate a relationship of the type 'Belong' This method triggers hydration of child objects.
public
hydrateBelongs(mixed $relation, mixed $data) : void
Parameters
- $relation : mixed
- $data : mixed
Return values
void —hydrateCustomClass()
Hydrates this instance with the data from the $data collection.
public
hydrateCustomClass(mixed $data[, string $alias = '' ]) : void
Only defined fields will be populated.
The counterpart of this class is 'hydrateFlex' which does the opposite.
Parameters
- $data : mixed
- $alias : string = ''
Return values
void —hydrateFlex()
Hydrate a Flex object.
public
hydrateFlex(mixed $data) : void
This required a specific method since Flex objects have no definition, so every field found in the $data collection will be set as an attribute.
Parameters
- $data : mixed
Return values
void —hydrateHas()
Hydrate a relationship of the type 'Has' This method triggers hydration of child objects.
public
hydrateHas(mixed $relation, mixed $data) : void
Parameters
- $relation : mixed
- $data : mixed
Return values
void —hydrateHasAndBelongs()
public
hydrateHasAndBelongs(mixed $relation, mixed $data) : mixed
Parameters
- $relation : mixed
- $data : mixed
Return values
mixed —hydrateRelations()
Hydrate all the relations found in the instance.
public
hydrateRelations(mixed $data) : void
Only the attributes present in the $data collection will be used to hydrate childs, so no queries will be executed to fetch relations from the database.
Parameters
- $data : mixed
Return values
void —isEmpty()
Determine if an object is empty
public
isEmpty() : bool
Return values
bool —isInternal()
Determine if it's an internal attribute
public
isInternal(string $name) : bool
Parameters
- $name : string
Return values
bool —isNew()
Check if it's a new instance or a loaded one
public
isNew() : bool
Return values
bool —meta()
Get the metadata of the object.
public
meta() : Meta
Return values
Meta —postDelete()
Method to be executed after deleting an object.
public
postDelete() : bool
Return values
bool —postSave()
Method to be executed after saving an object.
public
postSave() : bool
Return values
bool —preDelete()
Method to be executed before deleting an object.
public
preDelete() : bool
Return values
bool —preSave()
Method to be executed before saving an object.
public
preSave() : bool
Return values
bool —relations()
Get the relations manager object.
public
relations() : RelationsManager
Return values
RelationsManager —removeTableFields()
Remove all the fields related to an alias or table form the $data collection.
public
removeTableFields(mixed $alias, mixed $data) : array<string|int, mixed>
The idea here is that as soon as an object was hydrated it is removed from the data and perform a recursive hydration without that information until there's nothing to hydrate.
Parameters
- $alias : mixed
- $data : mixed
Return values
array<string|int, mixed> —toArray()
Helper method, turn input data to array
public
toArray(mixed $data) : array<string|int, mixed>
Parameters
- $data : mixed
Return values
array<string|int, mixed> —valid()
This method should be overriden for object validation.
public
valid() : bool