yii2-workflow Class Reference
  • Namespace
  • Class

Namespaces

  • raoul2000
    • workflow
      • actions
      • base
      • events
      • helpers
      • source
        • file
      • validation

Classes

  • DefaultArrayParser
  • GraphmlLoader
  • MinimalArrayParser
  • PhpArrayLoader
  • PhpClassLoader
  • WorkflowArrayParser
  • WorkflowDefinitionLoader
  • WorkflowFileSource

Interfaces

  • IWorkflowDefinitionProvider

Class WorkflowFileSource

This class provides workflow objects (Workflow, Status, Transitions) to the SimpleWorkflowBehavior behavior. The task of loading the workflow definition file, and turns it content into a normalized array, is delegated to a [[WorkflowDefinitionLoader]] instance. The definition loader can be initialized through the [[definitionLoader]] attribute.

yii\base\Object
Extended by raoul2000\workflow\source\file\WorkflowFileSource implements raoul2000\workflow\source\IWorkflowSource
Namespace: raoul2000\workflow\source\file
Located at source/file/WorkflowFileSource.php

Methods summary

public
# __construct( array $config = [] )

Constructor method.

Constructor method.

Parameters

$config
public raoul2000\workflow\source\file\WorkflowDefinitionLoader
# getDefinitionLoader( )

Returns the Workflow Definition Loader component. This component is created the first time this method is invoked (lazy loading).

Returns the Workflow Definition Loader component. This component is created the first time this method is invoked (lazy loading).

Returns

raoul2000\workflow\source\file\WorkflowDefinitionLoader
the workflow definition loader instance
public null|yii\caching\Cache
# getDefinitionCache( )

Return the workflow definition cache component used by this workflow source or NULL if no cache is used.

Return the workflow definition cache component used by this workflow source or NULL if no cache is used.

Returns

null|yii\caching\Cache

Throws

yii\base\InvalidConfigException
public raoul2000\workflow\base\Status
# getStatus( string $id, mixed $defaultWorkflowId = null )

Returns the status object instance whose id is passed as argument. If this status was never loaded before, it is loaded now and stored (cached) for later use.

Returns the status object instance whose id is passed as argument. If this status was never loaded before, it is loaded now and stored (cached) for later use.

If a $model is provided, it must be a BaseActiveRecord instance with a SimpleWorkflowBehavior attached. This model is used to complete the status ID if the one defined by the $id argument is not complete (e.g. 'draft' instead of 'post/draft').

Parameters

$id
ID of the status to get
$defaultWorkflowId
model instance used to resolve the status ID or workflow ID

Returns

raoul2000\workflow\base\Status
the status instance

Throws

raoul2000\workflow\base\WorkflowException
unexpected error

See

raoul2000\workflow\source\IWorkflowSource::getStatus()

Implementation of

raoul2000\workflow\source\IWorkflowSource::getStatus()
public raoul2000\workflow\base\TransitionInterface[]
# getTransitions( mixed $statusId, $defaultWorkflowId = null )

Returns all out going transitions leaving the status whose id is passed as argument. This method also create instances for the initial status and all statuses that can be reached from it.

Returns all out going transitions leaving the status whose id is passed as argument. This method also create instances for the initial status and all statuses that can be reached from it.

Parameters

$statusId
$defaultWorkflowId

Returns

raoul2000\workflow\base\TransitionInterface[]

an array containing all out going transition from $statusId. If no such transition exist, this method returns an empty array.

Throws

raoul2000\workflow\base\WorkflowException
unexpected error

See

IWorkflowSource::getTransitions()

Implementation of

raoul2000\workflow\source\IWorkflowSource::getTransitions()
public raoul2000\workflow\base\TransitionInterface
# getTransition( mixed $startId, mixed $endId, mixed $defaultWorkflowId = null )

Returns the transition between $startId and $endId statuses.

Returns the transition between $startId and $endId statuses.

Parameters

$startId
$endId
$defaultWorkflowId
$model

Returns

raoul2000\workflow\base\TransitionInterface
the transition between start and end status

See

IWorkflowSource::getTransition()

Implementation of

raoul2000\workflow\source\IWorkflowSource::getTransition()
public raoul2000\workflow\base\Workflow|null
# getWorkflow( mixed $id )

Returns the Workflow instance whose id is passed as argument.

Returns the Workflow instance whose id is passed as argument.

Parameters

$id
the workflow id

Returns

raoul2000\workflow\base\Workflow|null
The workflow instance or NULL if no workflow could be found

See

IWorkflowSource::getTransition()

Implementation of

raoul2000\workflow\source\IWorkflowSource::getWorkflow()
public
# getWorkflowDefinition( string $id )

Loads definition for the workflow whose id is passed as argument.

Loads definition for the workflow whose id is passed as argument.

The workflow Id passed as argument is used to create the class name of the object that holds the workflow definition.

Parameters

$id

Throws

raoul2000\workflow\base\WorkflowException
the definition could not be loaded
public string[]
# getClassMap( )

Returns the class map array for this Workflow source instance.

Returns the class map array for this Workflow source instance.

Returns

string[]
public string
# getClassMapByType( string $type )

Returns the class name that implement the type passed as argument. There are 3 built-in types that must have a class name :

Returns the class name that implement the type passed as argument. There are 3 built-in types that must have a class name :

  • self::TYPE_WORKFLOW
  • self::TYPE_STATUS
  • self::TYPE_TRANSITION

The constructor ensure that if a class map is provided, it include class names for these 3 types. Failure to do so will result in an exception being thrown by the constructor.

Parameters

$type
Type name

Returns

string
| null the class name or NULL if no class name is found forthis type.
public string[]
# parseStatusId( string $val, Model|string $helper = null )

Parses the string $val assuming it is a status id and returns and array containing the workflow ID and status local ID.

Parses the string $val assuming it is a status id and returns and array containing the workflow ID and status local ID.

If $val does not include the workflow ID part (i.e it is not in formated like "workflowID/statusID") this method uses $helper applying following rules : - if $helper is a string it is considered as the workflow Id - if $helper is an ActiveRecord instance and it is in a workflow, use it. If it is not in a workflow use its default workflow Id.

Parameters

$val

the status ID to parse. If it is not an absolute ID, $helper is used to get the workflow ID.

$helper
workflow Id or ActiveRecord instance used to get the workflow id if not present in $val

Returns

string[]

array containing the workflow ID in its first index, and the status Local ID in the second

Throws

raoul2000\workflow\base\WorkflowException
Exception thrown if the method was not able to parse $val.
public boolean
# isValidStatusId( string $id )

Checks if the string passed as argument can be used as a status ID.

Checks if the string passed as argument can be used as a status ID.

This method focuses on the status ID format and not on the fact that it actually refers to an existing status.

Parameters

$id
the status ID to test

Returns

boolean
TRUE if $id is a valid status ID, FALSE otherwise.

See

raoul2000\workflow\source\file\WorkflowFileSource::parseStatusId()
public boolean
# isValidWorkflowId( string $val )

Checks if the string passed as argument can be used as a workflow ID.

Checks if the string passed as argument can be used as a workflow ID.

A workflow ID is a string that matches self::PATTERN_ID.

Parameters

$val

Returns

boolean
TRUE if the $val can be used as workflow id, FALSE otherwise
public boolean
# isValidStatusLocalId( string $val )

Checks if the string passed as argument can be used as a status local ID.

Checks if the string passed as argument can be used as a status local ID.

Parameters

$val

Returns

boolean
public boolean
# addWorkflowDefinition( string $workflowId, array $definition, boolean $overwrite = false )

Add a workflow definition array to the collection of workflow definitions handled by this source. This method can be use for instance, by a model that holds the definition of the workflow it is using.
If a workflow with same id already exist in this source, it is overwritten if the last parameter is set to TRUE.

Add a workflow definition array to the collection of workflow definitions handled by this source. This method can be use for instance, by a model that holds the definition of the workflow it is using.
If a workflow with same id already exist in this source, it is overwritten if the last parameter is set to TRUE.

Parameters

$workflowId
Id of the workflow
$definition
array containing the workflow definition to process
$overwrite

When set to TRUE, the operation will fail if a workflow definition already exists for this ID. Otherwise the existing definition is overwritten.

Returns

boolean
TRUE if the workflow definition could be added, FALSE otherwise

See

raoul2000\workflow\base\SimpleWorkflowBehavior::attach()
public array
# validateWorkflowDefinition( string $wId, array $definition )

Validate the workflow definition passed as argument. The workflow definition array format is the one used internally by this class, and that should have been provided by the configured workflow definition provider component.

Validate the workflow definition passed as argument. The workflow definition array format is the one used internally by this class, and that should have been provided by the configured workflow definition provider component.

Parameters

$wId
Id of the workflow to validate
$definition
workflow definition

Returns

array
list of validation report
public raoul2000\workflow\base\StatusInterface[]
# getAllStatuses( string $workflowId )

Returns an array containing all statuses belonging to a workflow.

Returns an array containing all statuses belonging to a workflow.

Parameters

$workflowId
$id workflow Id

Returns

raoul2000\workflow\base\StatusInterface[]
list of status. The array key is the status ID

Throws

raoul2000\workflow\base\WorkflowException
no workflow is found with this Id

See

raoul2000\workflow\source\IWorkflowSource::getAllStatuses()

Implementation of

raoul2000\workflow\source\IWorkflowSource::getAllStatuses()

Constants summary

string PATTERN_ID

The regular expression used to validate status and workflow Ids.

The regular expression used to validate status and workflow Ids.

# '/^[a-zA-Z]+[[:alnum:]-]*$/'
string SEPARATOR_STATUS_NAME

The separator used to create a status id by concatenating the workflow id and the status local id (e.g. post/draft).

The separator used to create a status id by concatenating the workflow id and the status local id (e.g. post/draft).

# '/'
string KEY_NODES

Name of the array key for status list definition

Name of the array key for status list definition

# 'status'
string KEY_EDGES

Name of the key for transition list definition

Name of the key for transition list definition

# 'transition'
string KEY_METADATA

Name of the key for metadata definition

Name of the key for metadata definition

# 'metadata'
string DEFAULT_WDLOADER_CLASS

Name of the parser class that is used by default

Name of the parser class that is used by default

# '\raoul2000\workflow\source\file\PhpClassLoader'
string TYPE_STATUS

array key for status class in class map

array key for status class in class map

# 'status'
string TYPE_TRANSITION

array key for transition class in class map

array key for transition class in class map

# 'transition'
string TYPE_WORKFLOW

array key for workflow class in class map

array key for workflow class in class map

# 'workflow'

Properties summary

public string|array|raoul2000\workflow\source\file\WorkflowDefinitionLoader $definitionLoader

The workflow definition loader used by this source component can be be specified in one of the following forms :

  • string : ID of an existing workflow definition component registered in the current Yii::$app.
  • a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties
  • object : the instance of the workflow definition loader

Note that in all cases, the workflow definition loader configured here must implement the WorkflowDefinitionLoader interface.

If this attribute is not set then a default object of type \raoul2000\workflow\source\file\PhpClassLoader is used.

The workflow definition loader used by this source component can be be specified in one of the following forms :

  • string : ID of an existing workflow definition component registered in the current Yii::$app.
  • a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties
  • object : the instance of the workflow definition loader

Note that in all cases, the workflow definition loader configured here must implement the WorkflowDefinitionLoader interface.

If this attribute is not set then a default object of type \raoul2000\workflow\source\file\PhpClassLoader is used.

#
public string|array|yii\caching\Cache $definitionCache

The workflow definition cache used by this source component can be be specified in one of the following forms :

  • string : ID of an existing cache component registered in the current Yii::$app.
  • a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties
  • object : the instance of the cache component

By default no cache is used.

The workflow definition cache used by this source component can be be specified in one of the following forms :

  • string : ID of an existing cache component registered in the current Yii::$app.
  • a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties
  • object : the instance of the cache component

By default no cache is used.

#
yii2-workflow Class Reference API documentation generated by ApiGen