SimpleRecord
extends ActiveRecord
in package
An ActiveRecord with (generated) properties based on the ModelConfig->properties.
Adds the ActiveRecord interface to any Repository model, but disables support for property-autocompletion.
Table of Contents
- $_model : string
- The model in the repository, usually the same as the classname.
- $_repository : string|Repository
- The repository this instance belongs to.
- $_state : enum
- Persistance state: loaded: object was loaded from the persistance layer.
- $events : array<string|int, mixed>
- The events/listeners.
- $__kvo : array<string|int, mixed>
- Storage array for the properties with KVO (Key Value Observer) listeners.
- __call() : mixed
- Report that the $method doesn't exist.
- __callStatic() : mixed
- Report that the $method doesn't exist.
- __construct() : mixed
- Use the repostory or static functions to create an instance.
- __get() : mixed
- Report that $property doesn't exist.
- __set() : mixed
- Report that $property doesn't exist and set the property to the given $value.
- __toString() : string
- The object is used as an string.
- all() : Collection
- Retrieve a collection.
- create() : SimpleRecord
- Create a new instance.
- delete() : mixed
- Delete the instance from the persistance layer.
- getChanges() : array<string|int, mixed>
- Retrieve unsaved changes.
- hasEvent() : bool
- Check id the $event is a registered event.
- off() : mixed
- Remove a callback from an event.
- on() : string
- Add a callback for an event.
- one() : SimpleRecord
- Find an instance based on critera.
- save() : mixed
- Write the state to the persistance layer.
- trigger() : mixed
- Trigger an event.
- _getModel() : string
- Detect the modelname.
- _getRepostory() : Repository
- Detect the repository.
- onCreate() : mixed
- Handle the 'create' event.
- onDeleted() : mixed
- Handle the 'deleted' event.
- onLoad() : mixed
- Handle the 'load' event.
- onSaved() : mixed
- Handle the 'saved' event.
Properties
$_model
The model in the repository, usually the same as the classname.
protected
string
$_model
$_repository
The repository this instance belongs to.
protected
string|Repository
$_repository
$_state
Persistance state: loaded: object was loaded from the persistance layer.
protected
enum
$_state
= 'unconstructed'
new: object created, but not written to the persistance layer. saved: object has been saved to the persistance layer. deleted: object is deleted from the persistance layer.
$events
The events/listeners.
protected
array<string|int, mixed>
$events
= [
'create' => [],
// When a new instance is created (with initial data), but commited to the backend.
'load' => [],
// After the data from the backend is injected into the ActiveRecord.
'saving' => [],
// Before the data is sent to the backend
'saved' => [],
// After the data is sent to the backend
'deleting' => [],
// Before the delete operation is sent to the backend
'deleted' => [],
]
$__kvo
Storage array for the properties with KVO (Key Value Observer) listeners.
private
array<string|int, mixed>
$__kvo
= []
Methods
__call()
Report that the $method doesn't exist.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__callStatic()
Report that the $method doesn't exist.
public
static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__construct()
Use the repostory or static functions to create an instance.
public
__construct() : mixed
Tags
Return values
mixed —__get()
Report that $property doesn't exist.
public
__get(string $property) : mixed
Parameters
- $property : string
Return values
mixed —__set()
Report that $property doesn't exist and set the property to the given $value.
public
__set(mixed $property, mixed $value) : mixed
Parameters
- $property : mixed
- $value : mixed
Return values
mixed —__toString()
The object is used as an string.
public
__toString() : string
Return values
string —all()
Retrieve a collection.
public
static all([string $model = null ][, array<string|int, mixed> $options = [] ]) : Collection
Parameters
- $model : string = null
- $options : array<string|int, mixed> = []
Return values
Collection —create()
Create a new instance.
public
static create([string $model = null ][, array<string|int, mixed> $values = [] ][, array<string|int, mixed> $options = [] ]) : SimpleRecord
Parameters
- $model : string = null
-
(required)
- $values : array<string|int, mixed> = []
- $options : array<string|int, mixed> = []
-
array( 'repository' => (string) "default" )
Return values
SimpleRecord —delete()
Delete the instance from the persistance layer.
public
delete() : mixed
Return values
mixed —getChanges()
Retrieve unsaved changes.
public
getChanges() : array<string|int, mixed>
Return values
array<string|int, mixed> —hasEvent()
Check id the $event is a registered event.
public
hasEvent(string $event) : bool
Parameters
- $event : string
Return values
bool —off()
Remove a callback from an event.
public
off(string $event, string $identifier) : mixed
Parameters
- $event : string
- $identifier : string
Return values
mixed —on()
Add a callback for an event.
public
on(string $event, Closure|string|array<string|int, mixed> $callback) : string
Parameters
- $event : string
- $callback : Closure|string|array<string|int, mixed>
Return values
string —identifier
one()
Find an instance based on critera.
public
static one(string $model[, mixed $conditions = null ][, mixed $allowNone = false ][, array<string|int, mixed> $options = [] ]) : SimpleRecord
Parameters
- $model : string
- $conditions : mixed = null
- $allowNone : mixed = false
- $options : array<string|int, mixed> = []
-
array( 'repository' => (string) "default" 'preload' => (bool) false )
Return values
SimpleRecord —save()
Write the state to the persistance layer.
public
save([mixed $options = [] ]) : mixed
Parameters
- $options : mixed = []
Tags
Return values
mixed —trigger()
Trigger an event.
public
trigger(string $event, stdClass $sender[, mixed $args = null ]) : mixed
Parameters
- $event : string
- $sender : stdClass
- $args : mixed = null
-
(optional)
Return values
mixed —_getModel()
Detect the modelname.
protected
static _getModel([array<string|int, mixed> $options = [] ]) : string
Checks the $options array. Checks if the $_model property is defined in the subclass. Or defaults to the classname.
Parameters
- $options : array<string|int, mixed> = []
Return values
string —_getRepostory()
Detect the repository.
protected
static _getRepostory([array<string|int, mixed> $options = [] ]) : Repository
Checks the $options array. Checks if the $_repository property is defined in the subclass. Or uses the default repository.
Parameters
- $options : array<string|int, mixed> = []
Return values
Repository —onCreate()
Handle the 'create' event.
protected
onCreate(object $sender, array<string|int, mixed> $options) : mixed
Parameters
- $sender : object
- $options : array<string|int, mixed>
Return values
mixed —onDeleted()
Handle the 'deleted' event.
protected
onDeleted() : mixed
Return values
mixed —onLoad()
Handle the 'load' event.
protected
onLoad(object $sender, array<string|int, mixed> $options) : mixed
Parameters
- $sender : object
- $options : array<string|int, mixed>
Return values
mixed —onSaved()
Handle the 'saved' event.
protected
onSaved() : mixed