libSmalldb
v0.2
|
Implementation of the state machine. More...
Public Member Functions | |
__construct (AbstractBackend $backend, $type, $config, $context) | |
Constructor. More... | |
getState ($id) | |
Get current state of state machine. More... | |
getProperties ($id, &$state_cache=null) | |
Get properties of state machine, including it's state. More... | |
getView ($id, $view, &$properties_cache=null, &$view_cache=null, &$persistent_view_cache=null) | |
Get properties in given view. More... | |
isTransitionAllowed (Reference $ref, $transition_name, $state=null) | |
Returns true if transition can be invoked right now. More... | |
getAvailableTransitions (Reference $ref, $state=null) | |
Get list of all available actions for state machine instance identified by $id. | |
invokeTransition (Reference $ref, $transition_name, $args, &$returns, $new_id_callback=null) | |
Invoke state machine transition. More... | |
flushCache () | |
If machine properties are cached, flush all cached data. | |
getMachineType () | |
Get type of this machine. | |
getBackend () | |
Get backend which owns this machine. | |
ref ($id) | |
Helper to create Reference to this machine. More... | |
nullRef () | |
Helper to create null Reference to this machine. More... | |
hotRef ($properties) | |
Create pre-heated reference using properties loaded from elsewhere. More... | |
Public Attributes | |
const | RETURNS_VALUE = null |
Return value of invoked transition is just some value. | |
const | RETURNS_NEW_ID = 'new_id' |
Return value of invoked transition is new ID of the state machine. | |
Protected Member Functions | |
initializeMachine ($config) | |
Define state machine used by all instances of this type. | |
checkAccessPolicy ($access_policy, Reference $ref) | |
Returns true if user has required access_policy to invoke a transition, which requires given access_policy. | |
urlFormat ($id, $url_fmt, $properties_cache) | |
Create URL using properties and given format. | |
resolveMachineReference ($reference_name, $properties_cache) | |
Helper function to resolve reference to another machine. More... | |
onStateChanged (Reference $ref, $old_state, $transition_name, $new_state) | |
Called when state is changed, when transition invocation is completed. | |
Protected Attributes | |
$backend | |
Backend, where all machines are stored. | |
$context | |
Global context passed from backend. | |
$machine_type | |
Identification within $backend. | |
$url_fmt | |
URL format string where machine is located, usualy only the path part, e.g. More... | |
$parent_url_fmt | |
URL format string where parent of this machine is located, usualy only the path part, e.g. More... | |
$post_action_url_fmt | |
URL format string for redirect-after-post. More... | |
$states | |
Descriptions of all known states – key is state id, value is * description. More... | |
$state_groups | |
State groups. More... | |
$actions | |
Description of all known actions – key is action name. More... | |
$default_access_policy = null | |
Default access policy. More... | |
$read_access_policy = null | |
Read access policy. More... | |
$listing_access_policy = null | |
Listing access policy. More... | |
$access_policies | |
Access policies. More... | |
$properties | |
Description of machine properties – key is property name. More... | |
$views | |
Description of machine views – key is view name. More... | |
$references | |
Description of machine references. More... | |
Reflection API | |
describeId () | |
Reflection: Describe ID (primary key). More... | |
getUrlFormat () | |
Get URL format. More... | |
getParentUrlFormat () | |
Get prent URL format. More... | |
getPostActionUrlFormat () | |
Get URL for redirect-after-post. More... | |
getMachineImplementationMTime () | |
Get mtime of machine implementation. More... | |
getAllMachineStates ($having_section=null) | |
Reflection: Get all states. More... | |
describeMachineState ($state, $field=null) | |
Reflection: Describe given machine state. More... | |
describeAllMachineStates ($having_section=null) | |
Reflection: Describe all states. | |
getAllMachineActions ($having_section=null) | |
Reflection: Get all actions (transitions) More... | |
describeMachineAction ($action, $field=null) | |
Reflection: Describe given machine action (transition) More... | |
describeAllMachineActions ($having_section=null) | |
Reflection: Describe all actions (transitions) | |
getAllMachineProperties ($having_section=null) | |
Reflection: Get all properties. More... | |
describeMachineProperty ($property, $field=null) | |
Reflection: Describe given property. More... | |
describeAllMachineProperties ($having_section=null) | |
Reflection: Describe all properties. More... | |
getAllMachineViews ($having_section=null) | |
Reflection: Get all views. More... | |
describeMachineView ($view, $field=null) | |
Reflection: Describe given view. More... | |
describeAllMachineViews ($having_section=null) | |
Reflection: Describe all views. | |
getAllMachineReferences ($having_section=null) | |
Reflection: Get all references. More... | |
describeMachineReference ($reference, $field=null) | |
Reflection: Describe given reference. More... | |
describeAllMachineReferences ($having_section=null) | |
Reflection: Describe all references. | |
exportDot () | |
Export state machine to Graphviz source code. | |
Implementation of the state machine.
One instance of this class represents all machines of this type.
State machine always work with ID, never with Reference. References are decoded within backend.
Transition method should return FALSE when it has failed.
__construct | ( | AbstractBackend | $backend, |
$type, | |||
$config, | |||
$context | |||
) |
Constructor.
Machine gets reference to owning backend, name of its type (under which is this machine registered in backend) and optional array of additional configuration (passed directly to initializeMachine method).
|
abstract |
Get current state of state machine.
|
abstract |
Get properties of state machine, including it's state.
If state machine uses property views, not all properties may be returned by this method. Some of them may be computed or too big.
Some implementations may store current state to $state_cache, so it does not have to be retireved in the second query.
getView | ( | $id, | |
$view, | |||
& | $properties_cache = null , |
||
& | $view_cache = null , |
||
& | $persistent_view_cache = null |
||
) |
Get properties in given view.
Just like SQL view, the property view is transformed set of properties. These views are useful when some properties require heavy calculations.
Keep in mind, that view name must not interfere with Reference properties, otherwise the view is inaccessible directly.
Array $properties_cache is supplied by Reference class to make some calculations faster and without duplicate database queries. Make sure these cached properties are up to date or null.
Array $view_cache is writable cache inside the Reference class, flushed together with $properties_cache. If cache is empty, but available, an empty array is supplied.
Array $persistent_view_cache is kept untouched for entire Reference lifetime. If cache is empty, but available, an empty array is supplied.
/
|
protected |
Helper function to resolve reference to another machine.
$reference_name | Name of the reference in AbstractMachine::references. |
$properties_cache | Properties of referencing machine. |
isTransitionAllowed | ( | Reference | $ref, |
$transition_name, | |||
$state = null |
|||
) |
Returns true if transition can be invoked right now.
/
invokeTransition | ( | Reference | $ref, |
$transition_name, | |||
$args, | |||
& | $returns, | ||
$new_id_callback = null |
|||
) |
Invoke state machine transition.
State machine is not instance of this class, but it is represented by record in database.
ref | ( | $id | ) |
Helper to create Reference to this machine.
nullRef | ( | ) |
Helper to create null Reference to this machine.
hotRef | ( | $properties | ) |
Create pre-heated reference using properties loaded from elsewhere.
|
abstract |
Reflection: Describe ID (primary key).
Returns array of all parts of the primary key and its types (as strings). If primary key is not compound, something like array('id' => 'string') is returned.
Order of the parts may be mandatory.
getUrlFormat | ( | ) |
Get URL format.
Format string for Utils::filename_format().
getParentUrlFormat | ( | ) |
Get prent URL format.
Parent URL is URL of collection or something of which is this machine part of.
Format string for Utils::filename_format().
getPostActionUrlFormat | ( | ) |
Get URL for redirect-after-post.
Format string for Utils::filename_format().
getMachineImplementationMTime | ( | ) |
Get mtime of machine implementation.
Useful to detect outdated cache entry in generated documentation.
No need to override this method, it handles inherited classes correctly. However if machine is loaded from database, a new implementation is needed.
This does not include filemtime(FILE) intentionaly.
getAllMachineStates | ( | $having_section = null | ) |
Reflection: Get all states.
List of can be filtered by section, just like getAllMachineActions method does.
describeMachineState | ( | $state, | |
$field = null |
|||
) |
Reflection: Describe given machine state.
Returns state description in array or null. If field is specified, only given field is returned.
getAllMachineActions | ( | $having_section = null | ) |
Reflection: Get all actions (transitions)
List of actions can be filtered by section defined in action configuration. For example $this->getAllMachineStates('block') will return only actions which have 'block' configuration defined. Requested section must contain non-empty() value.
describeMachineAction | ( | $action, | |
$field = null |
|||
) |
Reflection: Describe given machine action (transition)
Returns action description in array or null. If field is specified, only given field is returned.
getAllMachineProperties | ( | $having_section = null | ) |
Reflection: Get all properties.
List of can be filtered by section, just like getAllMachineActions method does.
describeMachineProperty | ( | $property, | |
$field = null |
|||
) |
Reflection: Describe given property.
Returns property description in array or null. If field is specified, only given field is returned.
describeAllMachineProperties | ( | $having_section = null | ) |
Reflection: Describe all properties.
Returns array of all properties and their descriptions. See describeMachineProperty and getAllMachineProperties.
getAllMachineViews | ( | $having_section = null | ) |
Reflection: Get all views.
List of can be filtered by section, just like getAllMachineActions method does.
describeMachineView | ( | $view, | |
$field = null |
|||
) |
Reflection: Describe given view.
Returns view description in array or null. If field is specified, only given field is returned.
getAllMachineReferences | ( | $having_section = null | ) |
Reflection: Get all references.
List of can be filtered by section, just like getAllMachineActions method does.
describeMachineReference | ( | $reference, | |
$field = null |
|||
) |
Reflection: Describe given reference.
Returns reference description in array or null. If field is specified, only given field is returned.
|
protected |
URL format string where machine is located, usualy only the path part, e.g.
"/machine-type/{id}".
To make reverse routes work, only entire path fragment can be replaced by symbol:
This is limitation of default router, not this class.
If URL does not start with slash, router will ignore it.
|
protected |
URL format string where parent of this machine is located, usualy only the path part, e.g.
"/parent-type/{id}/machine-type".
|
protected |
URL format string for redirect-after-post.
When machine is part of another entity, it may be reasonable to redirect to such entity instead of showing this machine alone. If not set, url_fmt is used.
|
protected |
Descriptions of all known states – key is state id, value is * description.
Fill these data in self::initializeMachine().
|
protected |
State groups.
This state machine is flat – no sub-states. To make diagrams easier to read, this allows to group relevant states together. This has no influence on the behaviour.
Fill these data in self::initializeMachine().
|
protected |
Description of all known actions – key is action name.
Each action has transitions (transition function) and each transition can end in various different states (assertion function).
Fill these data in self::initializeMachine().
|
protected |
Default access policy.
When transition nor action has policy specified, this one is used.
|
protected |
Read access policy.
Policy applied when reading machine state.
|
protected |
Listing access policy.
Policy applied when creating machine listing (read_access_policy is also applied).
|
protected |
Access policies.
Description of all access policies available to this state machine type.
|
protected |
Description of machine properties – key is property name.
Each property has some metadata available, so it is possible to generate simple forms or present data to user without writing per-machine specific templates. These metadata should be as little implementation specific as possible.
|
protected |
Description of machine views – key is view name.
Some properties may require heavy computations and may not be used as often as other properties, so it is reasonable to put them into separate view instead.
These views are just like SQL views. They are somehow transformed view on the machine and its properties. There is no explicit definition of structure of the view – it can be single value, subset of properties, or something completely different.
View names must not collide with reference names, since references are special cases of views.
|
protected |
Description of machine references.
Often it is useful to reference one state machine from another, just like foreign keys in SQL.
Smalldb is limited to reference using primary keys only.
References are added to views.