PHP Class ezcWorkflowExecution, Workflow

ezcWorkflowExecution provides all functionality necessary to execute a workflow. However, it does not provide functionality to make the execution of a workflow persistent and hence usuable over more than one PHP run. Implementations must implement the do* methods and provide the means to store the execution data to a persistent medium.
Mostra file Open project: zetacomponents/workflow Class Usage Examples

Protected Properties

Property Type Description
$activatedNodes ezcWorkflowNode[] Nodes of the workflow being executed that are activated.
$cancelled boolean Flag that indicates whether or not this execution has been cancelled.
$ended boolean Flag that indicates whether or not this execution has ended.
$id integer Execution ID.
$nextThreadId integer Sequence for thread ids.
$numActivatedEndNodes integer Number of activated end nodes.
$numActivatedNodes integer Number of activated nodes.
$plugins array Plugins registered for this execution.
$properties array(string=>mixed) Container to hold the properties
$resumed boolean Flag that indicates whether or not this execution has been resumed.
$suspended boolean Flag that indicates whether or not this execution has been suspended.
$threads array Nodes of the workflow that started a new thread of execution.
$variables array Workflow variables.
$waitingFor array Workflow variables the execution is waiting for.

Public Methods

Method Description
__get ( string $propertyName ) : mixed Property read access.
__isset ( string $propertyName ) : boolean Property isset access.
__set ( string $propertyName, mixed $val ) Property write access.
activate ( ezcWorkflowNode $node, boolean $notifyPlugins = true ) : boolean Activates a node and returns true if it was activated, false if not.
addListener ( ezcWorkflowExecutionListener $listener ) : boolean Adds a listener to this execution.
addPlugin ( ezcWorkflowExecutionPlugin $plugin ) : boolean Adds a plugin to this execution.
addWaitingFor ( ezcWorkflowNode $node, string $variableName, ezcWorkflowCondition $condition ) Adds a variable that an (input) node is waiting for.
cancel ( ezcWorkflowNode $node = null ) Cancels workflow execution with the node $endNode.
end ( ezcWorkflowNode $node = null ) Ends workflow execution with the node $endNode.
endThread ( integer $threadId ) Ends the thread with id $threadId
getActivatedNodes ( ) : array Returns the activated nodes.
getId ( ) : integer Returns the execution ID.
getNumSiblingThreads ( integer $threadId ) : integer Returns the number of siblings for a given thread.
getParentThreadId ( integer $threadId ) : integer Returns the id of the parent thread for a given thread.
getSubExecution ( integer $id = null, boolean $interactive = true ) : ezcWorkflowExecution Returns a new execution object for a sub workflow.
getVariable ( string $variableName ) Returns a variable.
getVariables ( ) : array Returns the variables.
getWaitingFor ( ) : array Returns the variables that (input) nodes are waiting for.
hasEnded ( ) : boolean Returns true when the workflow execution has ended.
hasVariable ( string $variableName ) : boolean Checks whether or not a workflow variable has been set.
isCancelled ( ) : boolean Returns true when the workflow execution has been cancelled.
isResumed ( ) : boolean Returns true when the workflow execution has been resumed.
isSuspended ( ) : boolean Returns true when the workflow execution has been suspended.
removeListener ( ezcWorkflowExecutionListener $listener ) : boolean Removes a listener from this execution.
removePlugin ( ezcWorkflowExecutionPlugin $plugin ) : boolean Removes a plugin from this execution.
resume ( array $inputData = [] ) Resumes workflow execution of a suspended workflow.
setVariable ( string $variableName, mixed $value ) : mixed Sets a variable.
setVariables ( array $variables ) Sets the variables.
start ( integer $parentId = null ) : mixed Starts the execution of the workflow and returns the execution id.
startThread ( integer $parentId = null, integer $numSiblings = 1 ) : integer Start a new thread and returns the id of the new thread.
suspend ( ) Suspends workflow execution.
unsetVariable ( string $variableName ) : true, Unsets a variable.

Protected Methods

Method Description
doEnd ( ) Called by end() when workflow execution is ended.
doGetSubExecution ( integer $id = null ) : ezcWorkflowExecution Returns a new execution object for a sub workflow.
doResume ( ) Called by resume() when workflow execution is resumed.
doStart ( integer $parentId ) Called by start() when workflow execution is initiated.
doSuspend ( ) Called by suspend() when workflow execution is suspended.
execute ( ) The workflow engine's main execution loop. It is started by start() and resume().
loadFromVariableHandlers ( ) Loads data from variable handlers and merge it with the current execution data.
saveToVariableHandlers ( ) Saves data to execution data handlers.

Method Details

__get() public method

Property read access.
public __get ( string $propertyName ) : mixed
$propertyName string Name of the property.
return mixed Value of the property or null.

__isset() public method

Property isset access.
public __isset ( string $propertyName ) : boolean
$propertyName string Name of the property.
return boolean True is the property is set, otherwise false.

__set() public method

Property write access.
public __set ( string $propertyName, mixed $val )
$propertyName string Name of the property.
$val mixed The value for the property.

activate() public method

The node will only be activated if the node is executable. See {@link ezcWorkflowNode::isExecutable()}.
public activate ( ezcWorkflowNode $node, boolean $notifyPlugins = true ) : boolean
$node ezcWorkflowNode
$notifyPlugins boolean
return boolean

addListener() public method

Adds a listener to this execution.
public addListener ( ezcWorkflowExecutionListener $listener ) : boolean
$listener ezcWorkflowExecutionListener
return boolean true when the listener was added, false otherwise.

addPlugin() public method

Adds a plugin to this execution.
public addPlugin ( ezcWorkflowExecutionPlugin $plugin ) : boolean
$plugin ezcWorkflowExecutionPlugin
return boolean true when the plugin was added, false otherwise.

addWaitingFor() public method

Adds a variable that an (input) node is waiting for.
public addWaitingFor ( ezcWorkflowNode $node, string $variableName, ezcWorkflowCondition $condition )
$node ezcWorkflowNode
$variableName string
$condition ezcWorkflowCondition

cancel() public method

Cancels workflow execution with the node $endNode.
public cancel ( ezcWorkflowNode $node = null )
$node ezcWorkflowNode

doEnd() abstract protected method

Reimplementations can use this method to remove execution data from the persistent medium.
abstract protected doEnd ( )

doGetSubExecution() abstract protected method

Called by getSubExecution to get a new execution environment for the new execution thread. Reimplementations must return a new execution environment similar to themselves.
abstract protected doGetSubExecution ( integer $id = null ) : ezcWorkflowExecution
$id integer
return ezcWorkflowExecution

doResume() abstract protected method

Reimplementations can use this method to fetch execution data if necessary..
abstract protected doResume ( )

doStart() abstract protected method

Reimplementations can use this method to store workflow information to a persistent medium when execution is started.
abstract protected doStart ( integer $parentId )
$parentId integer

doSuspend() abstract protected method

Reimplementations can use this method to variable and node information to a persistent medium.
abstract protected doSuspend ( )

end() public method

End nodes must call this method to end the execution.
public end ( ezcWorkflowNode $node = null )
$node ezcWorkflowNode

endThread() public method

Ends the thread with id $threadId
public endThread ( integer $threadId )
$threadId integer

execute() protected method

The workflow engine's main execution loop. It is started by start() and resume().
protected execute ( )

getActivatedNodes() public method

Returns the activated nodes.
public getActivatedNodes ( ) : array
return array

getId() public method

Returns the execution ID.
public getId ( ) : integer
return integer

getNumSiblingThreads() public method

Returns the number of siblings for a given thread.
public getNumSiblingThreads ( integer $threadId ) : integer
$threadId integer The id of the thread for which to return the number of siblings.
return integer

getParentThreadId() public method

Returns the id of the parent thread for a given thread.
public getParentThreadId ( integer $threadId ) : integer
$threadId integer The id of the thread for which to return the parent thread id.
return integer

getSubExecution() public method

If this method is used to resume a subworkflow you must provide the execution id through $id. If $interactive is false an ezcWorkflowExecutionNonInteractive will be returned. This method can be used by nodes implementing sub-workflows to get a new execution environment for the subworkflow.
public getSubExecution ( integer $id = null, boolean $interactive = true ) : ezcWorkflowExecution
$id integer
$interactive boolean
return ezcWorkflowExecution

getVariable() public method

Returns a variable.
public getVariable ( string $variableName )
$variableName string

getVariables() public method

Returns the variables.
public getVariables ( ) : array
return array

getWaitingFor() public method

Returns the variables that (input) nodes are waiting for.
public getWaitingFor ( ) : array
return array

hasEnded() public method

Returns true when the workflow execution has ended.
public hasEnded ( ) : boolean
return boolean

hasVariable() public method

Checks whether or not a workflow variable has been set.
public hasVariable ( string $variableName ) : boolean
$variableName string
return boolean true when the variable exists and false otherwise.

isCancelled() public method

Returns true when the workflow execution has been cancelled.
public isCancelled ( ) : boolean
return boolean

isResumed() public method

Returns true when the workflow execution has been resumed.
public isResumed ( ) : boolean
return boolean

isSuspended() public method

Returns true when the workflow execution has been suspended.
public isSuspended ( ) : boolean
return boolean

loadFromVariableHandlers() protected method

Loads data from variable handlers and merge it with the current execution data.
protected loadFromVariableHandlers ( )

removeListener() public method

Removes a listener from this execution.
public removeListener ( ezcWorkflowExecutionListener $listener ) : boolean
$listener ezcWorkflowExecutionListener
return boolean true when the listener was removed, false otherwise.

removePlugin() public method

Removes a plugin from this execution.
public removePlugin ( ezcWorkflowExecutionPlugin $plugin ) : boolean
$plugin ezcWorkflowExecutionPlugin
return boolean true when the plugin was removed, false otherwise.

resume() public method

$executionId is the id of the execution to resume. $inputData is an associative array of the format array( 'variable name' => value ) that should contain new workflow variable data required to resume execution. Calls do doResume() before the variables are loaded using the variable handlers.
public resume ( array $inputData = [] )
$inputData array The new input data.

saveToVariableHandlers() protected method

Saves data to execution data handlers.
protected saveToVariableHandlers ( )

setVariable() public method

Sets a variable.
public setVariable ( string $variableName, mixed $value ) : mixed
$variableName string
$value mixed
return mixed the value that the variable has been set to

setVariables() public method

Sets the variables.
public setVariables ( array $variables )
$variables array

start() public method

$parentId is used to specify the execution id of the parent workflow when executing subworkflows. It should not be used when manually starting workflows. Calls doStart() right before the first node is activated.
public start ( integer $parentId = null ) : mixed
$parentId integer
return mixed Execution ID if the workflow has been suspended, null otherwise.

startThread() public method

Start a new thread and returns the id of the new thread.
public startThread ( integer $parentId = null, integer $numSiblings = 1 ) : integer
$parentId integer The id of the parent thread.
$numSiblings integer The number of threads that are started by the same node.
return integer

suspend() public method

This method is usually called by the execution environment when there are no more more activated nodes that can be executed. This is commonly the case with input nodes waiting for input. This method calls doSuspend() before calling saveToVariableHandlers() allowing reimplementations to save variable and node information.
public suspend ( )

unsetVariable() public method

Unsets a variable.
public unsetVariable ( string $variableName ) : true,
$variableName string
return true,

Property Details

$activatedNodes protected_oe property

Nodes of the workflow being executed that are activated.
protected ezcWorkflowNode[] $activatedNodes
return ezcWorkflowNode[]

$cancelled protected_oe property

Flag that indicates whether or not this execution has been cancelled.
protected bool $cancelled
return boolean

$ended protected_oe property

Flag that indicates whether or not this execution has ended.
protected bool $ended
return boolean

$id protected_oe property

Execution ID.
protected int $id
return integer

$nextThreadId protected_oe property

Sequence for thread ids.
protected int $nextThreadId
return integer

$numActivatedEndNodes protected_oe property

Number of activated end nodes.
protected int $numActivatedEndNodes
return integer

$numActivatedNodes protected_oe property

Number of activated nodes.
protected int $numActivatedNodes
return integer

$plugins protected_oe property

Plugins registered for this execution.
protected array $plugins
return array

$properties protected_oe property

Container to hold the properties
protected array(string=>mixed) $properties
return array(string=>mixed)

$resumed protected_oe property

Flag that indicates whether or not this execution has been resumed.
protected bool $resumed
return boolean

$suspended protected_oe property

Flag that indicates whether or not this execution has been suspended.
protected bool $suspended
return boolean

$threads protected_oe property

Nodes of the workflow that started a new thread of execution.
protected array $threads
return array

$variables protected_oe property

Workflow variables.
protected array $variables
return array

$waitingFor protected_oe property

Workflow variables the execution is waiting for.
protected array $waitingFor
return array