PHP Class raoul2000\workflow\source\file\WorkflowFileSource

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.
Inheritance: extends yii\base\Object, implements raoul2000\workflow\source\IWorkflowSource
Datei anzeigen Open project: raoul2000/yii2-workflow Class Usage Examples

Public Properties

Property Type Description
$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.
$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.

Public Methods

Method Description
__construct ( array $config = [] ) Constructor method.
addWorkflowDefinition ( string $workflowId, array $definition, boolean $overwrite = false ) : boolean Add a workflow definition array to the collection of workflow definitions handled by this source.
getAllStatuses ( $workflowId ) Returns an array containing all statuses belonging to a workflow.
getClassMap ( ) : string[] Returns the class map array for this Workflow source instance.
getClassMapByType ( string $type ) : string | null Returns the class name that implement the type passed as argument.
getDefinitionCache ( ) : null | yii\caching\Cache Return the workflow definition cache component used by this workflow source or NULL if no cache is used.
getDefinitionLoader ( ) : WorkflowDefinitionLoader Returns the Workflow Definition Loader component.
getStatus ( string $id, mixed $defaultWorkflowId = null ) : Status Returns the status object instance whose id is passed as argument.
getTransition ( $startId, $endId, $defaultWorkflowId = null ) Returns the transition between $startId and $endId statuses.
getTransitions ( $statusId, $defaultWorkflowId = null ) Returns all out going transitions leaving the status whose id is passed as argument.
getWorkflow ( $id ) : Workflow | null Returns the Workflow instance whose id is passed as argument.
getWorkflowDefinition ( string $id ) Loads definition for the workflow whose id is passed as argument.
isValidStatusId ( string $id ) : boolean Checks if the string passed as argument can be used as a status ID.
isValidStatusLocalId ( string $val ) : boolean Checks if the string passed as argument can be used as a status local ID.
isValidWorkflowId ( string $val ) : boolean Checks if the string passed as argument can be used as a workflow ID.
parseStatusId ( string $val, Model | string $helper = null ) : string[] Parses the string $val assuming it is a status id and returns and array containing the workflow ID and status local ID.
validateWorkflowDefinition ( string $wId, array $definition ) : array Validate the workflow definition passed as argument.

Method Details

__construct() public method

Constructor method.
public __construct ( array $config = [] )
$config array

addWorkflowDefinition() public method

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.
See also: raoul2000\workflow\base\SimpleWorkflowBehavior::attach()
public addWorkflowDefinition ( string $workflowId, array $definition, boolean $overwrite = false ) : boolean
$workflowId string Id of the workflow
$definition array array containing the workflow definition to process
$overwrite boolean When set to TRUE, the operation will fail if a workflow definition already exists for this ID. Otherwise the existing definition is overwritten.
return boolean TRUE if the workflow definition could be added, FALSE otherwise

getAllStatuses() public method

Returns an array containing all statuses belonging to a workflow.
See also: raoul2000\workflow\source\IWorkflowSource::getAllStatuses()
public getAllStatuses ( $workflowId )

getClassMap() public method

Returns the class map array for this Workflow source instance.
public getClassMap ( ) : string[]
return string[]

getClassMapByType() public method

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.
public getClassMapByType ( string $type ) : string | null
$type string Type name
return string | null | null the class name or NULL if no class name is found forthis type.

getDefinitionCache() public method

Return the workflow definition cache component used by this workflow source or NULL if no cache is used.
public getDefinitionCache ( ) : null | yii\caching\Cache
return null | yii\caching\Cache

getDefinitionLoader() public method

This component is created the first time this method is invoked (lazy loading).
public getDefinitionLoader ( ) : WorkflowDefinitionLoader
return WorkflowDefinitionLoader the workflow definition loader instance

getStatus() public method

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').
See also: raoul2000\workflow\source\IWorkflowSource::getStatus
public getStatus ( string $id, mixed $defaultWorkflowId = null ) : Status
$id string ID of the status to get
$defaultWorkflowId mixed model instance used to resolve the status ID or workflow ID
return raoul2000\workflow\base\Status the status instance

getTransition() public method

Returns the transition between $startId and $endId statuses.
See also: IWorkflowSource::getTransition()
public getTransition ( $startId, $endId, $defaultWorkflowId = null )

getTransitions() public method

This method also create instances for the initial status and all statuses that can be reached from it.
See also: IWorkflowSource::getTransitions()
public getTransitions ( $statusId, $defaultWorkflowId = null )

getWorkflow() public method

Returns the Workflow instance whose id is passed as argument.
See also: IWorkflowSource::getTransition()
public getWorkflow ( $id ) : Workflow | null
return raoul2000\workflow\base\Workflow | null The workflow instance or NULL if no workflow could be found

getWorkflowDefinition() public method

The workflow Id passed as argument is used to create the class name of the object that holds the workflow definition.
public getWorkflowDefinition ( string $id )
$id string

isValidStatusId() public method

This method focuses on the status ID format and not on the fact that it actually refers to an existing status.
See also: WorkflowFileSource::parseStatusId()
public isValidStatusId ( string $id ) : boolean
$id string the status ID to test
return boolean TRUE if $id is a valid status ID, FALSE otherwise.

isValidStatusLocalId() public method

Checks if the string passed as argument can be used as a status local ID.
public isValidStatusLocalId ( string $val ) : boolean
$val string
return boolean

isValidWorkflowId() public method

A workflow ID is a string that matches self::PATTERN_ID.
public isValidWorkflowId ( string $val ) : boolean
$val string
return boolean TRUE if the $val can be used as workflow id, FALSE otherwise

parseStatusId() public method

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.
public parseStatusId ( string $val, Model | string $helper = null ) : string[]
$val string the status ID to parse. If it is not an absolute ID, $helper is used to get the workflow ID.
$helper Model | string workflow Id or ActiveRecord instance used to get the workflow id if not present in $val
return string[] array containing the workflow ID in its first index, and the status Local ID in the second

validateWorkflowDefinition() public method

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.
public validateWorkflowDefinition ( string $wId, array $definition ) : array
$wId string Id of the workflow to validate
$definition array workflow definition
return array list of validation report

Property Details

$definitionCache public_oe property

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.
public $definitionCache

$definitionLoader public_oe property

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 $definitionLoader