* $workflow = new ezcWorkflow( 'Test' );
*
* $input = new ezcWorkflowNodeInput( "mixedVar" => new ezcWorkflowConditionIsAnything,
* "intVar" => new ezcWorkflowConditionAnd(
* array(
* new ezcWorkflowConditionIsInteger,
* new ezcWorkflowConditionIsGreatherThan( 0 )
* new ezcWorkflowConditionIsLessThan( 11 )
* )
* ) );
*
* $input->addOutNode( $workflow->endNode );
* $workflow->startNode->addOutNode( $input );
*
* @package Workflow
* @version 1.0
*/
class ezcWorkflowNodeInput extends ezcWorkflowNode
{
/**
* Constructs a new input node.
*
* An input node accepts an array of workflow variables to accept
* and/or together with a condition on the variable if required.
*
* Each element in the configuration array must be either
* String: The name of the workflow variable to require. No conditions.
*
* or
*
* - Key: The name of the workflow variable to require.
* - Value: An object of type ezcWorkflowCondition
*
*
* @param mixed $configuration
* @throws ezcBaseValueException
*/
public function __construct( $configuration = '' )
{
if ( !is_array( $configuration ) )
{
throw new ezcBaseValueException(
'configuration', $configuration, 'array'
);
}
$tmp = array();
foreach ( $configuration as $key => $value )
{
if ( is_int( $key ) )
{
if ( !is_string( $value ) )
{
throw new ezcBaseValueException(
'workflow variable name', $value, 'string'
);
}
$variable = $value;
$condition = new ezcWorkflowConditionIsAnything;
}
else
{
if ( !is_object( $value ) || !$value instanceof ezcWorkflowCondition )
{
throw new ezcBaseValueException(
'workflow variable condition', $value, 'ezcWorkflowCondition'
);
}
$variable = $key;
$condition = $value;
}
$tmp[$variable] = $condition;
}
parent::__construct( $tmp );
}
/**
* Executes this node.
*
* @param ezcWorkflowExecution $execution
* @ignore
*/
public function execute( ezcWorkflowExecution $execution )
{
$variables = $execution->getVariables();
$canExecute = true;
foreach ( $this->configuration as $variable => $condition )
{
if ( !isset( $variables[$variable] ) )
{
$execution->addWaitingFor( $this, $variable, $condition );
$canExecute = false;
}
}
if ( $canExecute )
{
$this->activateNode( $execution, $this->outNodes[0] );
return parent::execute( $execution );
}
else
{
return false;
}
}
}
?>