The Exclusive Choice workflow pattern defines multiple possible paths for the workflow of which exactly one is chosen based on the conditions set for the out nodes. Incoming nodes: 1 Outgoing nodes: 2..* This example displays how you can use an exclusive choice to select one of two possible branches depending on the workflow variable 'value' which is read using an input node. new ezcWorkflowConditionIsInt ) ); $workflow->startNode->addOutNode( $input ); create the exclusive choice branching node $choice = new ezcWorkflowNodeExclusiveChoice; $intput->addOutNode( $choice ); $branch1 = ....; // create nodes for the first branch of execution here.. $branch2 = ....; // create nodes for the second branch of execution here.. add the outnodes and set the conditions on the exclusive choice $choice->addConditionalOutNode( new ezcWorkflowConditionVariable( 'value', new ezcWorkflowConditionGreaterThan( 10 ) ), $branch1 ); $choice->addConditionalOutNode( new ezcWorkflowConditionVariable( 'value', new ezcWorkflowConditionLessThan( 11 ) ), $branch2 ); Merge the two branches together and continue execution. $merge = new ezcWorkflowNodeSimpleMerge(); $merge->addInNode( $branch1 ); $merge->addInNode( $branch2 ); $merge->addOutNode( $workflow->endNode ); ?>
Inheritance: extends ezcWorkflowNodeConditionalBranch
示例#1
0
 protected function setUpNestedExclusiveChoiceSimpleMerge($x = true, $y = true)
 {
     $this->workflow = new ezcWorkflow('NestedExclusiveChoiceSimpleMerge');
     $setX = new ezcWorkflowNodeVariableSet(array('x' => $x));
     $setY = new ezcWorkflowNodeVariableSet(array('y' => $y));
     $setZ1 = new ezcWorkflowNodeVariableSet(array('z' => true));
     $setZ2 = new ezcWorkflowNodeVariableSet(array('z' => false));
     $setZ3 = new ezcWorkflowNodeVariableSet(array('z' => false));
     $this->workflow->startNode->addOutNode($setX);
     $branch1 = new ezcWorkflowNodeExclusiveChoice();
     $branch1->addInNode($setX);
     $branch1->addConditionalOutNode(new ezcWorkflowConditionVariable('x', new ezcWorkflowConditionIsTrue()), $setY);
     $branch1->addConditionalOutNode(new ezcWorkflowConditionVariable('x', new ezcWorkflowConditionIsFalse()), $setZ3);
     $branch2 = new ezcWorkflowNodeExclusiveChoice();
     $branch2->addInNode($setY);
     $branch2->addConditionalOutNode(new ezcWorkflowConditionVariable('y', new ezcWorkflowConditionIsTrue()), $setZ1);
     $branch2->addConditionalOutNode(new ezcWorkflowConditionVariable('y', new ezcWorkflowConditionIsFalse()), $setZ2);
     $nestedMerge = new ezcWorkflowNodeSimpleMerge();
     $nestedMerge->addInNode($setZ1)->addInNode($setZ2);
     $merge = new ezcWorkflowNodeSimpleMerge();
     $merge->addInNode($nestedMerge)->addInNode($setZ3)->addOutNode($this->workflow->endNode);
 }
示例#2
0
<?php

// Create new workflow of name "Test".
$workflow = new ezcWorkflow('Test');
// Create an Input node that expects a boolean workflow variable of name "choice".
$input = new ezcWorkflowNodeInput(array('choice' => new ezcWorkflowConditionIsBool()));
// Add the previously created Input node
// as an outgoing node to the start node.
$workflow->startNode->addOutNode($input);
// Create a new Exclusive Choice node and add it as an
// outgoing node to the previously created Input node.
// This node will choose which output to run based on the
// choice workflow variable.
$branch = new ezcWorkflowNodeExclusiveChoice();
$branch->addInNode($input);
// Either $true or $false will be run depending on
// the above choice.
// Note that neither $true nor $false are valid action nodes.
// see the next example
$trueNode = new ezcWorkflowNodeAction('PrintTrue');
$falseNode = new ezcWorkflowNodeAction('PrintFalse');
// Branch
// Condition: Variable "choice" has boolean value "true".
// Action:    PrintTrue service object.
$branch->addConditionalOutNode(new ezcWorkflowConditionVariable('choice', new ezcWorkflowConditionIsTrue()), $trueNode);
// Branch
// Condition: Variable "choice" has boolean value "false".
// Action:    PrintFalse service object.
$branch->addConditionalOutNode(new ezcWorkflowConditionVariable('choice', new ezcWorkflowConditionIsFalse()), $falseNode);
// Create SimpleMerge node and add the two possible threads of
// execution as incoming nodes of the end node.
示例#3
0
文件: node_test.php 项目: bmdevel/ezc
 public function testVerifyTooFewConditionalOutNodes()
 {
     $branch = new ezcWorkflowNodeExclusiveChoice();
     $branch->addInNode(new ezcWorkflowNodeStart())->addOutNode(new ezcWorkflowNodeEnd())->addOutNode(new ezcWorkflowNodeEnd());
     try {
         $branch->verify();
     } catch (ezcWorkflowInvalidWorkflowException $e) {
         $this->assertEquals('Node has less conditional outgoing nodes than required.', $e->getMessage());
         return;
     }
     $this->fail('Expected an ezcWorkflowInvalidWorkflowException to be thrown.');
 }