libSmalldb  v0.5
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Reference Class Reference

Description

Reference to one or more state machines.

Allows you to invoke transitions in the easy way by calling methods on this reference object. This is syntactic sugar only, nothing really happens here.

$id is per machine type unique identifier. It is always a single literal or an array of literals for compound primary keys.

Method call on this class invokes the transition.

Read-only properties:

Read one property (will load all of them): $ref['property']

Flush property cache: unset($ref->properties);

Inheritance diagram for Reference

Public Member Functions

 __construct (AbstractMachine $machine, $id=null)
 Create reference and initialize it with given ID. More...
 
 __debugInfo ()
 Show relevant data when using var_dump(). More...
 
 jsonSerialize ()
 Support for json_encode() - implementation of JsonSerializable interface. More...
 
 isNullRef ()
 Returns true if reference points only to machine type. More...
 
 __call ($name, $arguments)
 Function call is transition invocation. More...
 
 __get ($key)
 Get data from machine. More...
 
 __unset ($key)
 Flush cached data. More...
 

Static Public Member Functions

static createPreheatedReference ($machine, $properties)
 Create pre-heated reference. More...
 

Protected Member Functions

 emit ($callback_list)
 Call all registered callbacks when event happens. More...
 
 clearCache ()
 Drop all cached data. More...
 

Protected Attributes

 $machine
 State machine. More...
 
 $id
 Primary key (unique within $machine). More...
 
 $state_cache
 Cached state of the machine. More...
 
 $properties_cache
 Cached properties of the machine. More...
 
 $view_cache
 Cached values from views on machine properties. More...
 
 $persistent_view_cache = array()
 Persistent view cache, which is not flushed automaticaly after every transition. More...
 

Callbacks

Callbacks are lists of callables.

Reference calls them when something interesting happens.

To register a callable simply add it to the list.

 $pk_changed_cb = array()
 List of callbacks called when reference primary key changes. More...
 
 $before_transition_cb = array()
 List of callbacks called before transition is invoked. More...
 
 $after_transition_cb = array()
 List of callbacks called after transition is invoked. More...
 

Array access for properties

 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 

Iterator interface to iterate over properties

 rewind ()
 
 current ()
 
 key ()
 
 next ()
 
 valid ()
 

Constructor & Destructor Documentation

__construct ( AbstractMachine  $machine,
  $id = null 
)

Create reference and initialize it with given ID.

To copy a reference use clone keyword.

Todo:
Check $id to be made of scalar values only.

Member Function Documentation

__debugInfo ( )

Show relevant data when using var_dump().

jsonSerialize ( )

Support for json_encode() - implementation of JsonSerializable interface.

static createPreheatedReference (   $machine,
  $properties 
)
static

Create pre-heated reference.

Warning
This may break things a lot. Be careful.
emit (   $callback_list)
protected

Call all registered callbacks when event happens.

isNullRef ( )

Returns true if reference points only to machine type.

Such reference may not be used to modify any machine, however, it can be used to invoke 'create'-like transitions.

clearCache ( )
protected

Drop all cached data.

__call (   $name,
  $arguments 
)

Function call is transition invocation.

Just forward it to backend.

When transition returns new ID, the reference is updated to keep it pointing to the same state machine.

__get (   $key)

Get data from machine.

If you want to retrieve both state and properties, ask for properties first. The state may get pre-cached.

__unset (   $key)

Flush cached data.

Member Data Documentation

$machine
protected

State machine.

$id
protected

Primary key (unique within $machine).

$state_cache
protected

Cached state of the machine.

$properties_cache
protected

Cached properties of the machine.

$view_cache
protected

Cached values from views on machine properties.

$persistent_view_cache = array()
protected

Persistent view cache, which is not flushed automaticaly after every transition.

$pk_changed_cb = array()

List of callbacks called when reference primary key changes.

Just append callable to this array:

$ref->on_pk_change[] = function($ref, $new_pk) { };

$before_transition_cb = array()

List of callbacks called before transition is invoked.

Just append callable to this array:

$ref->before_transition_cb[] = function($ref, $transition_name, $arguments) { };

$after_transition_cb = array()

List of callbacks called after transition is invoked.

Just append callable to this array:

$ref->after_transition_cb[] = function($ref, $transition_name, $arguments, $return_value, $returns) { };