Smalldb  v0.0-177-g1a83180
 All Classes Namespaces Functions Variables Pages
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...
 
 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.
 

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.

Here is the call graph for this function:

Member Function Documentation

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.

__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) { };