libSmalldb  v0.7
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FlupdoBackend Class Reference

Description

Smalldb Backend which provides database via Flupdo.

Todo:
Make this dumb and provide it from somewhere else.
Deprecated:
Use JsonDirBackend instead.

Inheritance diagram for FlupdoBackend

Public Member Functions

 __construct ($options, $context, $alias)
 Constructor compatible with cascade resource factory. More...
 
 addType ($type, $class, $args=array(), $description=array())
 Register new state machine of type $type named $name, which is instance of class $class. More...
 
 addAllTypes ($mahine_types)
 Load all types at once. More...
 
 createQueryBuilder ($type)
 
 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
 __construct ($options, $context=null, $alias)
 Initialize backend. More...
 
 setDebugLogger (IDebugLogger $debug_logger)
 Set debug logger. More...
 
 getDebugLogger ()
 Get debug logger. More...
 
 getAlias ()
 Get current alias. More...
 
 afterReferenceCreated ()
 Get afterReferenceCreated hook. More...
 
 afterListingCreated ()
 Get afterListingCreated hook. More...
 
 setContext ($context)
 Set context if not set yet. More...
 
 getContext ($resource_name=null)
 Get context object (whatever it is). More...
 
 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. More...
 
 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...
 
 listing ($query_filters, $filtering_flags=0)
 Create a listing using given query filters via createListing() method. More...
 
 performSelfCheck ()
 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

 createListing ($filters, $filtering_flags=0)
 Creates a listing using given filters. More...
 
 createMachine ($type)
 Factory method: Prepare state machine of given type - a model shared between multiple real statemachines stored in backend. More...
 
- Protected Member Functions inherited from AbstractBackend
 createMachine ($type)
 Factory method: Prepare state machine of given type - a model shared between multiple real statemachines stored in backend. More...
 
 createListing ($query_filters, $filtering_flags=0)
 Create a listing using given query filters. More...
 

Protected Attributes

 $flupdo
 Database connection. More...
 
 $machine_type_table
 Static table of known machine types. More...
 

Constructor & Destructor Documentation

__construct (   $options,
  $context,
  $alias 
)

Constructor compatible with cascade resource factory.

Member Function Documentation

addType (   $type,
  $class,
  $args = array(),
  $description = array() 
)

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

And when creating this machine, pass $args to its constructor. Also additional meta-data can be attached using $description (will be merged with name, class and args).

addAllTypes (   $mahine_types)

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.

createListing (   $filters,
  $filtering_flags = 0 
)
protected

Creates a listing using given filters.

createQueryBuilder (   $type)
Deprecated:
This should not be here.
Todo:
This should be machine listing, not general query builder.
getKnownTypes ( )

Get all known state machine types.

Returns array of strings.

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

Member Data Documentation

$flupdo
protected

Database connection.

$machine_type_table
protected
Initial value:
= array(
)

Static table of known machine types.

Inherit this class and replace this table, or use 'machine_types' option when creating this backend.

Each record is also passed to AbstractMachine::initializeMachine().