libSmalldb  v0.7-37-g795340f
Public Member Functions | Protected Member Functions | List of all members
AbstractBackend Class Reference

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.

Inheritance diagram for AbstractBackend

Public Member Functions

 initializeBackend (array $config)
 Configure backend using the $configuration. More...
 
 isBackendInitialized ()
 Is this backend initialized? More...
 
 setDebugLogger (IDebugLogger $debug_logger)
 Set debug logger. More...
 
 getDebugLogger ()
 Get debug logger. More...
 
 afterReferenceCreated ()
 Get afterReferenceCreated hook. More...
 
 afterListingCreated ()
 Get afterListingCreated hook. More...
 
 inferMachineType ($aref, & $type, & $id)
 Infer type of referenced machine type. More...
 
 getCachedMachinesCount ()
 Get number of instantiated machines in cache. More...
 
 getMachine (Smalldb $smalldb, string $type)
 Get state machine of given type, create it if necessary. More...
 
 listing (Smalldb $smalldb, $query_filters, $filtering_flags=0)
 Create a listing using given query filters via createListing() method. More...
 
 performSelfCheck (Smalldb $smalldb)
 Perform a quick self-check to detect most common errors (but not all of them). More...
 

Protected Member Functions

 createMachine (Smalldb $smalldb, string $type)
 Factory method: Prepare state machine of given type - a model shared between multiple real statemachines stored in backend. More...
 
 createListing (Smalldb $smalldb, $query_filters, $filtering_flags=0)
 Create a listing using given query filters. 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...
 

Member Function Documentation

◆ initializeBackend()

initializeBackend ( array  $config)

Configure backend using the $configuration.

This method must be called soon after the instance is created.

◆ isBackendInitialized()

isBackendInitialized ( )

Is this backend initialized?

Note that in the case the initialization has failed, this still may be set to true.

◆ setDebugLogger()

setDebugLogger ( IDebugLogger  $debug_logger)

Set debug logger.

◆ getDebugLogger()

getDebugLogger ( )

Get debug logger.

◆ afterReferenceCreated()

afterReferenceCreated ( )

Get afterReferenceCreated hook.

◆ afterListingCreated()

afterListingCreated ( )

Get afterListingCreated hook.

◆ inferMachineType()

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

◆ createMachine()

createMachine ( Smalldb  $smalldb,
string  $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.

◆ getCachedMachinesCount()

getCachedMachinesCount ( )

Get number of instantiated machines in cache.

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

◆ getMachine()

getMachine ( Smalldb  $smalldb,
string  $type 
)

Get state machine of given type, create it if necessary.

◆ listing()

listing ( Smalldb  $smalldb,
  $query_filters,
  $filtering_flags = 0 
)
final

Create a listing using given query filters via createListing() method.

See also
createListing()
Returns
IListing.

◆ createListing()

createListing ( Smalldb  $smalldb,
  $query_filters,
  $filtering_flags = 0 
)
abstractprotected

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

◆ performSelfCheck()

performSelfCheck ( Smalldb  $smalldb)

Perform a quick self-check to detect most common errors (but not all of them).

This will throw various exceptions on errors.

Returns
array Array with the results (machine type -> per-machine results).

◆ getKnownTypes()

getKnownTypes ( )
abstract

Get all known state machine types.

Returns array of strings.

◆ describeType()

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',
    ...
)