Smalldb  v0.0-177-g1a83180
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | List of all members
AbstractBackend Class Reference

Container and factory of all state machines. More...

Inheritance diagram for AbstractBackend:
Inheritance graph

Public Member Functions

 __construct ($options, $context, $alias)
 Initialize backend. More...
 
 getAlias ()
 Get current alias.
 
 getContext ()
 Get context object (whatever it is).
 
 inferMachineType ($aref, &$type, &$id)
 Infer type of referenced machine type. More...
 
 getCachedMachinesCount ()
 Get number of instantiated machines in cache. More...
 
 getMachine ($type)
 Get state machine of given type, create it if necessary.
 
 ref ($arg1)
 Get reference to state machine instance of given type and id. More...
 
 nullRef ($type)
 Get reference to non-existent state machine instance of given type. More...
 
 flushCache ()
 Flush caches of all machines.
 
 createListing ($query_filters)
 Creates a listing using given query filters. More...
 

Protected Member Functions

 createMachine ($type)
 Factory method: Prepare state machine of given type - a model shared between multiple real statemachines stored in backend. More...
 

Reflection API

 getKnownTypes ()
 Get all known state machine types. More...
 
 describeType ($type)
 Describe given type without creating an instance of related state machine. More...
 

Detailed Description

Container and factory of all state machines.

It creates state machines when required and caches them for further use. Backend also knows what types of state machines can create and knows few useful details about them.

This is where References come from.

Constructor & Destructor Documentation

__construct (   $options,
  $context,
  $alias 
)

Initialize backend.

$alias is used for debugging and logging. Options should contain all required backend-specific data for backend initialization.

Parameters
$optionsare used by derived classes to configure everything.
$contextis accessible to AbstractMachine.
$aliasis used to identify instances in log.

Member Function Documentation

inferMachineType (   $aref,
$type,
$id 
)
abstract

Infer type of referenced machine type.

Returns true if decoding is successful, $type and $id are set to decoded values. Otherwise returns false.

Since references are global identifier, this method identifies the type of referenced machine. In simple cases it maps part of ref to type, in more complex scenarios it may ask database.

In simple applications ref consists of pair $type and $id, where $id is uniquie within given $type.

$aref is array of arguments passed to ref() or single literal if only one argument was passed.

$type is string.

$id is literal or array of literals (in case of compound key).

Here is the caller graph for this function:

createMachine (   $type)
abstractprotected

Factory method: Prepare state machine of given type - a model shared between multiple real statemachines stored in backend.

Do not forget that actual machine is not reachable, you only get this interface.

This creates only implementation of the machine, not concrete instance. See AbstractMachine.

Returns descendant of AbstractMachine or null.

Here is the caller graph for this function:

getCachedMachinesCount ( )

Get number of instantiated machines in cache.

Useful for statistics and check whether backend has not been used yet.

Here is the caller graph for this function:

ref (   $arg1)

Get reference to state machine instance of given type and id.

If the first argument is instance of Reference, this makes copy of it. If the first argument is an array, it will be used instead of all arguments.

These calls are equivalent:

$ref = $this->ref('item', 1, 2, 3);
$ref = $this->ref(array('item', 1, 2, 3));
$ref = $this->ref($this->ref('item', 1, 2, 3)));

Here is the call graph for this function:

nullRef (   $type)

Get reference to non-existent state machine instance of given type.

You may want to invoke 'create' or similar transition using this reference.

Here is the call graph for this function:

createListing (   $query_filters)
abstract

Creates a listing using given query filters.

Listing class is inferred from the query filters, callers should not expect any particular class to be used. This allows to replace listing classes at any time without breaking anything.

This method does not perform any query on its own, it only determines which query should be done and returns appropriate listing object.

Returns instance of IListing.

getKnownTypes ( )
abstract

Get all known state machine types.

Returns array of strings.

describeType (   $type)
abstract

Describe given type without creating an instance of related state machine.

Intended as data source for user interface generators (menu, navigation, ...).

Returns machine description as propery-value pairs in array. There are few well-known property names which should be used if possible. Any unknown properties will be ignored.

array(
    // Human-friendly name of the type
    'name' => 'Foo Bar',
    // Human-friendly description (one short paragraph, plain text)
    'desc' => 'Lorem ipsum dolor sit amet, ...',
    // Name of the file containing full machine definition
    'src'  => 'example/foo.json',
    ...
)