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

Reference to one or more state machines. More...

Inheritance diagram for Reference:
Inheritance graph

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().
 
 jsonSerialize ()
 Support for json_encode() - implementation of JsonSerializable interface.
 
 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.
 

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.
 
 clearCache ()
 Drop all cached data.
 

Protected Attributes

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

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 ()
 

Detailed 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);

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.

Here is the call graph for this function:

Member Function Documentation

static createPreheatedReference (   $machine,
  $properties 
)
static

Create pre-heated reference.

Warning
This may break things a lot. Be careful.

Here is the caller graph for this function:

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.

Here is the caller graph for this function:

__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.

Here is the call graph for this function:

__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.

Member Data Documentation

$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->on_pk_change[] = function($ref, $transition_name, $arguments) { };

$after_transition_cb = array()

List of callbacks called after transition is invoked.

Just append callable to this array:

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