libSmalldb  v0.7-66-gb94d22a
Public Member Functions | Protected Member Functions | List of all members
SimpleBackend Class Reference

Description

Simple and stupid backend which must be told about everything.

Good enough if configuration is loaded by some other part of application from config files, but too dumb to scan database automatically.

References are expected to be a pair of $type and $id, where $id is integer or string.

Inheritance diagram for SimpleBackend

Public Member Functions

 setStateMachineServiceLocator (ContainerInterface $service_locator=null)
 Set container which is then used to instantiate state machines. More...
 
 registerMachineType (string $type, string $class, array $configuration)
 Register new state machine of type $type named $name, which is instance of class $class. More...
 
 registerAllMachineTypes (array $machine_type_table)
 Load all types at once. More...
 
 getKnownTypes ()
 Get all known state machine types. More...
 
 describeType ($type)
 Describe given type without creating an instance of related state machine. More...
 
 inferMachineType ($aref, & $type, & $id)
 Infer type of referenced machine type using lookup table. More...
 
- Public Member Functions inherited from AbstractBackend
 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...
 
 getKnownTypes ()
 Get all known state machine types. More...
 
 describeType ($type)
 Describe given type without creating an instance of related state machine. 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, $filters, $filtering_flags=0)
 Creates a listing using given filters. More...
 
- Protected Member Functions inherited from AbstractBackend
 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...
 

Member Function Documentation

◆ setStateMachineServiceLocator()

setStateMachineServiceLocator ( ContainerInterface  $service_locator = null)

Set container which is then used to instantiate state machines.

Parameters
ContainerInterface$service_locator

◆ registerMachineType()

registerMachineType ( string  $type,
string  $class,
array  $configuration 
)

Register new state machine of type $type named $name, which is instance of class $class.

Also additional meta-data can be attached using $description (will be merged with name, class and args).

Parameters
string$typeType to register
string$classState machine implementation. It will be instantiated from the container.
array$configurationConfiguration of the state machine.

◆ registerAllMachineTypes()

registerAllMachineTypes ( array  $machine_type_table)

Load all types at once.

Argument must be exactly the same as return value of getKnownTypes method (array of arrays). Useful for loading types from cache.

◆ getKnownTypes()

getKnownTypes ( )

Get all known state machine types.

Returns
string[]

◆ describeType()

describeType (   $type)

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

◆ inferMachineType()

inferMachineType (   $aref,
$type,
$id 
)

Infer type of referenced machine type using lookup table.

Reference is pair: Table name + Primary key.

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 AbstractBackend::ref().

$type is string.

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

◆ createMachine()

createMachine ( Smalldb  $smalldb,
string  $type 
)
protected

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.

◆ createListing()

createListing ( Smalldb  $smalldb,
  $filters,
  $filtering_flags = 0 
)
protected

Creates a listing using given filters.

Todo:
: Support complex filtering over multiple machine types and make 'type' filter optional.
See also
AbstractBackend::createListing()