This example shows how to connect all signals to the slots provided by an
object.
- <?php
- // Connect signals to slots.
- $signals = new ezcSignalCollection;
- $receiver = new MyReceiver;
-
- $signals->connect( 'afterExecutionStarted', array( $receiver, 'afterExecutionStarted' ) );
- $signals->connect( 'afterExecutionSuspended', array( $receiver, 'afterExecutionSuspended' ) );
- $signals->connect( 'afterExecutionResumed', array( $receiver, 'afterExecutionResumed' ) );
- $signals->connect( 'afterExecutionCancelled', array( $receiver, 'afterExecutionCancelled' ) );
- $signals->connect( 'afterExecutionEnded', array( $receiver, 'afterExecutionEnded' ) );
- $signals->connect( 'beforeNodeActivated', array( $receiver, 'beforeNodeActivated' ) );
- $signals->connect( 'afterNodeActivated', array( $receiver, 'afterNodeActivated' ) );
- $signals->connect( 'afterNodeExecuted', array( $receiver, 'afterNodeExecuted' ) );
- $signals->connect( 'afterRolledBackServiceObject', array( $receiver, 'afterRolledBackServiceObject' ) );
- $signals->connect( 'afterThreadStarted', array( $receiver, 'afterThreadStarted' ) );
- $signals->connect( 'afterThreadEnded', array( $receiver, 'afterThreadEnded' ) );
- $signals->connect( 'beforeVariableSet', array( $receiver, 'beforeVariableSet' ) );
- $signals->connect( 'afterVariableSet', array( $receiver, 'afterVariableSet' ) );
- $signals->connect( 'beforeVariableUnset', array( $receiver, 'beforeVariableUnset' ) );
- $signals->connect( 'afterVariableUnset', array( $receiver, 'afterVariableUnset' ) );
-
- // Set up database connection.
- $db = ezcDbFactory::create( 'mysql://test@localhost/test' );
-
- // Set up workflow definition storage (database).
- $definition = new ezcWorkflowDatabaseDefinitionStorage( $db );
-
- // Load latest version of workflow named "Test".
- $workflow = $definition->loadByName( 'Test' );
-
- // Set up database-based workflow executer.
- $execution = new ezcWorkflowDatabaseExecution( $db );
-
- // Pass workflow object to workflow executer.
- $execution->workflow = $workflow;
-
- // Register SignalSlot workflow engine plugin.
- $plugin = new ezcWorkflowSignalSlotPlugin;
- $plugin->signals = $signals;
-
- $execution->addPlugin( $plugin );
-
- // Start workflow execution.
- $id = $execution->start();
- ?>
This is a dummy implementation of the MyReceiver class.
- <?php
- class MyReceiver
- {
- public function afterExecutionStarted( ezcWorkflowExecution $execution )
- {
- }
-
- public function afterExecutionSuspended( ezcWorkflowExecution $execution )
- {
- }
-
- public function afterExecutionResumed( ezcWorkflowExecution $execution )
- {
- }
-
- public function afterExecutionCancelled( ezcWorkflowExecution $execution )
- {
- }
-
- public function afterExecutionEnded( ezcWorkflowExecution $execution )
- {
- }
-
- public function beforeNodeActivated( ezcWorkflowExecution $execution, ezcWorkflowNode $node, ezcWorkflowSignalSlotReturnValue $return )
- {
- }
-
- public function afterNodeActivated( ezcWorkflowExecution $execution, ezcWorkflowNode $node )
- {
- }
-
- public function afterNodeExecuted( ezcWorkflowExecution $execution, ezcWorkflowNode $node )
- {
- }
-
- public function afterThreadStarted( ezcWorkflowExecution $execution, $threadId, $parentId, $numSiblings )
- {
- }
-
- public function afterThreadEnded( ezcWorkflowExecution $execution, $threadId )
- {
- }
-
- public function beforeVariableSet( ezcWorkflowExecution $execution, $variableName, $value, ezcWorkflowSignalSlotReturnValue $return )
- {
- }
-
- public function afterVariableSet( ezcWorkflowExecution $execution, $variableName, $value )
- {
- }
-
- public function beforeVariableUnset( ezcWorkflowExecution $execution, $variableName, ezcWorkflowSignalSlotReturnValue $return )
- {
- }
-
- public function afterVariableUnset( ezcWorkflowExecution $execution, $variableName )
- {
- }
- }
- ?>
Slots that receive an ezcWorkflowSignalSlotReturnValue object are special in the
way that they can control if and how the current execution step will be
performed. For more information on this advice mechanism please refer to the
documentation of the workflow engine plugin system.
For more information on using the SignalSlot component please refer to its
documentation.