libSmalldb  v0.7
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

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

Hooks

Hooks are lists of callables.

Reference calls them when something interesting happens.

See also
Hook class
 afterPkChanged ()
 Hook invoked when reference primary key changes. More...
 
 beforeTransition ()
 Hook invoked before transition is invoked. More...
 
 afterTransition ()
 Hook invoked 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

afterPkChanged ( )

Hook invoked when reference primary key changes.

Callback: function($ref, $new_pk)

beforeTransition ( )

Hook invoked before transition is invoked.

Callback: function($ref, $transition_name, $arguments)

afterTransition ( )

Hook invoked after transition is invoked.

Callback: function($ref, $transition_name, $arguments, $return_value, $returns)

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