* $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.1rc1 */ 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 * * @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; } } /** * Generate node configuration from XML representation. * * @param DOMElement $element */ public static function configurationFromXML( DOMElement $element ) { $configuration = array(); foreach ( $element->getElementsByTagName( 'variable' ) as $variable ) { $configuration[$variable->getAttribute( 'name' )] = ezcWorkflowDefinitionStorageXml::xmlToCondition( $variable->childNodes->item( 1 ) ); } return $configuration; } /** * Generate XML representation of this node's configuration. * * @param DOMElement $element */ public function configurationToXML( DOMElement $element ) { foreach ( $this->configuration as $variable => $condition ) { $xmlVariable = $element->appendChild( $element->ownerDocument->createElement( 'variable' ) ); $xmlVariable->setAttribute( 'name', $variable ); $xmlVariable->appendChild( ezcWorkflowDefinitionStorageXml::conditionToXml( $condition, $element->ownerDocument ) ); } } } ?>